rest

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LangDefault = "zh-CN"
	AcceptLang  = "Accept-Language"
)
View Source
const (
	AlgorithmHS256 = "HS256"
)

Variables

View Source
var (
	StatusOK    = 0
	StatusError = 100

	MsgOK     = "OK"
	MsgFAIL   = "FAIL"
	EmptyData = map[string]any{}
)
View Source
var (
	DefaultJWTConfig = JWTConfig{
		SigningMethod: AlgorithmHS256,
		TokenLookup:   "header:Authorization",
		AuthScheme:    "Bearer",
		Claims:        jwt.MapClaims{},
	}
)

Functions

func HttpLanguage

func HttpLanguage(req *http.Request) string

func Msg

func Msg(msg string, msgs ...string) string

Types

type Ele

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

type I18n

type I18n interface {
	HttpValue(req *http.Request, key, defaultVal string, params ...string) string
	LangValue(lang, key, defaultVal string, params ...string) string
	Append(i18nDir string) error
}

func InitI18n

func InitI18n(i18nDir string) (I18n, error)

type JWTConfig

type JWTConfig struct {
	SigningMethod  string
	SigningKey     any
	AuthScheme     string
	TokenLookup    string
	Expires        time.Duration
	SigningKeys    map[string]any
	Claims         jwt.Claims
	KeyFunc        jwt.Keyfunc
	ParseTokenFunc func(auth string) (*jwt.Token, error)
}

func JWT

func JWT(key string, expires int64) *JWTConfig

func (*JWTConfig) DefaultKeyFunc

func (config *JWTConfig) DefaultKeyFunc(t *jwt.Token) (any, error)

func (*JWTConfig) DefaultParseToken

func (config *JWTConfig) DefaultParseToken(tokenstr string) (token *jwt.Token, err error)

func (*JWTConfig) DefaultTokenGenerator

func (config *JWTConfig) DefaultTokenGenerator(fn func() (jwt.MapClaims, error)) (string, time.Time, error)

type Response

type Response struct {
	Status int    `json:"status"`
	Data   any    `json:"data"`
	Msg    string `json:"msg"`
}

func Fail

func Fail() Response

func FailWithData

func FailWithData(data any, msgs ...string) Response

func FailWithMessage

func FailWithMessage(msg string) Response

func OK

func OK() Response

func OkWithData

func OkWithData(data any, msgs ...string) Response

func OkWithMessage

func OkWithMessage(msg string) Response

Jump to

Keyboard shortcuts

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