utils

package
v0.0.0-...-fae7c5d Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmailVerificationPurpose = "v"
	PasswordResetPurpose     = "r"
)
View Source
const (
	RequestIdKey = "X-Oneapi-Request-Id"
)

Variables

View Source
var VerificationValidMinutes = 10

Functions

func AsString

func AsString(v any) string

func AssignOrDefault

func AssignOrDefault(value string, defaultValue string) string

func BanUser

func BanUser(id int)

func Bool

func Bool(env string, defaultValue bool) bool

func Bytes2Size

func Bytes2Size(num int64) string

func CalcElapsedTime

func CalcElapsedTime(start time.Time) int64

CalcElapsedTime return the elapsed time in milliseconds (ms)

func DeDuplication

func DeDuplication(slice []string) []string

func DeleteKey

func DeleteKey(key string, purpose string)

func Done

func Done(c *gin.Context)

func EmbedFolder

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

func Float64

func Float64(env string, defaultValue float64) float64

func Float64PtrMax

func Float64PtrMax(p *float64, maxValue float64) *float64

func Float64PtrMin

func Float64PtrMin(p *float64, minValue float64) *float64

func GenRequestID

func GenRequestID() string

func GenerateKey

func GenerateKey() string

func GenerateVerificationCode

func GenerateVerificationCode(length int) string

func GetIp

func GetIp() (ip string)

func GetRandomNumberString

func GetRandomNumberString(length int) string

func GetRandomString

func GetRandomString(length int) string

func GetRequestBody

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

func GetRequestID

func GetRequestID(ctx context.Context) string

func GetResponseID

func GetResponseID(c *gin.Context) string

func GetTimeString

func GetTimeString() string

func GetTimestamp

func GetTimestamp() int64

func GetUUID

func GetUUID() string

func Int

func Int(env string, defaultValue int) int

func IntMax

func IntMax(a int, b int) int

func Interface2String

func Interface2String(inter interface{}) string

func IsUserBanned

func IsUserBanned(id int) bool

func Max

func Max(a int, b int) int

func MessageWithRequestId

func MessageWithRequestId(message string, id string) string

func ObjectData

func ObjectData(c *gin.Context, object interface{}) error

func OpenBrowser

func OpenBrowser(url string)

func Password2Hash

func Password2Hash(password string) (string, error)

func RandRange

func RandRange(min, max int) int

RandRange returns a random number between min and max (max is not included)

func RegisterVerificationCodeWithKey

func RegisterVerificationCodeWithKey(key string, code string, purpose string)

func SetEventStreamHeaders

func SetEventStreamHeaders(c *gin.Context)

func SetRequestID

func SetRequestID(ctx context.Context, id string) context.Context

func String

func String(env string, defaultValue string) string

func String2Int

func String2Int(str string) int

func StringData

func StringData(c *gin.Context, str string)

func UnbanUser

func UnbanUser(id int)

func UnescapeHTML

func UnescapeHTML(x string) interface{}

func UnmarshalBodyReusable

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

func ValidatePasswordAndHash

func ValidatePasswordAndHash(password string, hash string) bool

func VerifyCodeWithKey

func VerifyCodeWithKey(key string, code string, purpose 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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