common

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 25 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Port         = flag.Int("port", 3000, "the listening port")
	PrintVersion = flag.Bool("version", false, "print version and exit")
	PrintHelp    = flag.Bool("help", false, "print help and exit")
	LogDir       = flag.String("log-dir", "", "specify the log directory")
)
View Source
var RedisEnabled = true
View Source
var SQLiteBusyTimeout = env.Int("SQLITE_BUSY_TIMEOUT", 3000)
View Source
var SQLitePath = "myapi.db"
View Source
var StartTime = time.Now().Unix() // unit: second
View Source
var UsingMySQL = false
View Source
var UsingPostgreSQL = false
View Source
var UsingSQLite = false
View Source
var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change

Functions

func EmbedFolder

func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem

func GenerateJWT

func GenerateJWT(userId int, username string, role int, status int) (string, error)

func GetRequestBody

func GetRequestBody(c *gin.Context) ([]byte, error)

func Init

func Init()

func InitRedisClient

func InitRedisClient() (err error)

InitRedisClient This function is called after init()

func LogQuota

func LogQuota(quota int64) string

func ParseRedisOption

func ParseRedisOption() *redis.Options

func Password2Hash

func Password2Hash(password string) (string, error)

func RedisDecrease

func RedisDecrease(key string, value int64) error

func RedisDel

func RedisDel(key string) error

func RedisGet

func RedisGet(key string) (string, error)

func RedisSet

func RedisSet(key string, value string, expiration time.Duration) error

func SetEventStreamHeaders

func SetEventStreamHeaders(c *gin.Context)

func UnmarshalBodyReusable

func UnmarshalBodyReusable(c *gin.Context, v any) error

func ValidatePasswordAndHash

func ValidatePasswordAndHash(password string, hash string) bool

Types

type CustomEvent

type CustomEvent struct {
	Event string
	Id    string
	Retry uint
	Data  interface{}
}

func (CustomEvent) Render

func (r CustomEvent) Render(w http.ResponseWriter) error

func (CustomEvent) WriteContentType

func (r CustomEvent) WriteContentType(w http.ResponseWriter)

type InMemoryRateLimiter

type InMemoryRateLimiter struct {
	// contains filtered or unexported fields
}

func (*InMemoryRateLimiter) Init

func (l *InMemoryRateLimiter) Init(expirationDuration time.Duration)

func (*InMemoryRateLimiter) Request

func (l *InMemoryRateLimiter) Request(key string, maxRequestNum int, duration int64) bool

Request parameter duration's unit is seconds

type JWTClaims

type JWTClaims struct {
	UserId   int    `json:"user_id"`
	Username string `json:"username"`
	Role     int    `json:"role"`
	Status   int    `json:"status"`
	jwt.StandardClaims
}

func ParseJWT

func ParseJWT(tokenString string) (*JWTClaims, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL