common

package
v1.0.23 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger *logrus.Logger = logrus.New()

Functions

func GetAppConfig

func GetAppConfig[T int | uint | int64 | uint64 | bool | string | []any | map[string]any](s *AppModel, key string, defaultValue T) T

func GetEnvConfig

func GetEnvConfig[T int | uint | int64 | uint64 | bool | string | []any | map[string]any](s *AppModel, env *utils.EnvGetter) T

func SetBootContext

func SetBootContext(bootContext *BootContext)

Types

type AppModel

type AppModel struct {
	AppId   int64  `json:"appId,string"` // 应用id
	AppCode string `json:"appCode"`      // 应用标识
	AppName string `json:"appName"`      // 应用名称
	// contains filtered or unexported fields
}

func (AppModel) Config

func (s AppModel) Config() map[string]any

func (AppModel) Get

func (s AppModel) Get(key string) (any, bool)

func (*AppModel) SetConfig

func (s *AppModel) SetConfig(config string)

type AppModelHandler

type AppModelHandler = func(c *gin.Context, appCode string) *AppModel

type BootContext

type BootContext struct {
	Xorm            *xorm.Engine
	Redis           *redis.Client
	SessionHandle   gin.HandlerFunc
	Logger          *logrus.Logger
	TokenHandlers   map[string]TokenHandler
	AppModdelHandle AppModelHandler
	LogHandle       LogHandler
	Routes          []*Route
	Tasks           map[string][]gin.HandlerFunc
	Addr            string
	// contains filtered or unexported fields
}

func GetBootContext

func GetBootContext() *BootContext

func NewBootContext added in v1.0.9

func NewBootContext() *BootContext

func (*BootContext) Get added in v1.0.9

func (s *BootContext) Get(key string) any

func (*BootContext) GetTokenHandler added in v1.0.19

func (s *BootContext) GetTokenHandler(key string) TokenHandler

func (*BootContext) Install

func (s *BootContext) Install(r *gin.Engine, plugins ...BootPlugin)

func (*BootContext) Load added in v1.0.9

func (s *BootContext) Load(key string) (any, bool)

func (*BootContext) PrintAddr

func (s *BootContext) PrintAddr()

func (*BootContext) Set added in v1.0.9

func (s *BootContext) Set(key string, value any)

func (*BootContext) SetTokenHandler added in v1.0.19

func (s *BootContext) SetTokenHandler(key string, handler TokenHandler)

func (*BootContext) WithRoutes

func (s *BootContext) WithRoutes(routes ...[]*Route)

func (*BootContext) WithTask

func (s *BootContext) WithTask(tasks map[string][]gin.HandlerFunc)

type BootPlugin

type BootPlugin func(ctx *BootContext, r *gin.Engine)

type LogHandler

type LogHandler func(c *gin.Context, tableId int, opId LogOpType, primaryId int64, data any)

type LogOpType

type LogOpType int16

Dblog

const (
	LogOpNormal LogOpType = 0 // 常规
	LogOpInsert LogOpType = 1 // 更新记录
	LogOpUpdate LogOpType = 2 // 更新记录
	LogOpDelete LogOpType = 3 // 删除记录
	LogOpDrop   LogOpType = 4 // 彻底删除记录
)

type Route

type Route struct {
	Name       string
	Path       string
	Method     string
	EnsureAuth bool
	NoAppCode  bool
	Handle     gin.HandlerFunc
	TokenKey   string
}

路由定义

type TokenHandler

type TokenHandler = func(c *gin.Context, token string) *UserToken

type UserInfo

type UserInfo struct {
	UserId   int64  `json:"userId,string,omitempty" `
	Nickname string `json:"nickname,omitempty" `
	Avatar   string `json:"avatar,omitempty" `
}

type UserToken

type UserToken struct {
	UserInfo         UserInfo  `json:"userInfo"`
	AccessToken      string    `json:"accessToken"`
	RefreshToken     string    `json:"refreshToken"`
	CreatedAt        time.Time `json:"createdAt"`
	AccessExpiredAt  time.Time `json:"accessExpiredAt"`
	RefreshExpiredAt time.Time `json:"refreshExpiredAt"`
	TokenKey         string    `json:"tokenKey"`
}

func (UserToken) IsTokenExpired

func (s UserToken) IsTokenExpired() bool

Jump to

Keyboard shortcuts

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