common

package
v1.0.58 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 9 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 NewLogModule added in v1.0.38

func NewLogModule(name string) *logrus.Entry

func NewLogModules added in v1.0.45

func NewLogModules(name string, subs ...string) []*logrus.Entry

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
	AppModelHandle AppModelHandler
	LogHandle      LogHandler
	Routes         []*Route
	Tasks          map[string][]gin.HandlerFunc
	Addr           string

	IpEngine *geoip2.Reader
	// 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) WithRoutesQs added in v1.0.26

func (s *BootContext) WithRoutesQs(routes []*Route, routeQS *RouteQS)

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
	Label      string
	Path       string
	Method     string
	EnsureAuth bool
	NoAppCode  bool
	Handle     RouteHandler
	TokenKey   string
}

路由定义

func (*Route) WithAuth added in v1.0.27

func (s *Route) WithAuth(value bool) *Route

func (*Route) WithLabel added in v1.0.27

func (s *Route) WithLabel(value string) *Route

func (*Route) WithMethod added in v1.0.27

func (s *Route) WithMethod(value string) *Route

func (*Route) WithName added in v1.0.27

func (s *Route) WithName(value string) *Route

func (*Route) WithNoAppCode added in v1.0.27

func (s *Route) WithNoAppCode(value bool) *Route

func (*Route) WithPath added in v1.0.27

func (s *Route) WithPath(value string) *Route

func (*Route) WithTokenKey added in v1.0.27

func (s *Route) WithTokenKey(value string) *Route

type RouteBuilder added in v1.0.29

type RouteBuilder struct {
	RouteQS
	// contains filtered or unexported fields
}

func NewRouteBuidler added in v1.0.29

func NewRouteBuidler() *RouteBuilder

func (*RouteBuilder) AddRoute added in v1.0.29

func (s *RouteBuilder) AddRoute(path string, handler RouteHandler) *RouteBuilder

func (*RouteBuilder) Result added in v1.0.29

func (s *RouteBuilder) Result() ([]*Route, *RouteQS)

func (*RouteBuilder) WithAuth added in v1.0.30

func (s *RouteBuilder) WithAuth(value bool) *RouteBuilder

func (*RouteBuilder) WithLabel added in v1.0.30

func (s *RouteBuilder) WithLabel(value string) *RouteBuilder

func (*RouteBuilder) WithMethod added in v1.0.30

func (s *RouteBuilder) WithMethod(value string) *RouteBuilder

func (*RouteBuilder) WithName added in v1.0.30

func (s *RouteBuilder) WithName(value string) *RouteBuilder

func (*RouteBuilder) WithNoAppCode added in v1.0.30

func (s *RouteBuilder) WithNoAppCode(value bool) *RouteBuilder

func (*RouteBuilder) WithTokenKey added in v1.0.30

func (s *RouteBuilder) WithTokenKey(value string) *RouteBuilder

type RouteHandler added in v1.0.27

type RouteHandler func(ctx *gin.Context)

func (RouteHandler) Route added in v1.0.27

func (s RouteHandler) Route() *Route

type RouteQS added in v1.0.26

type RouteQS struct {
	Name       *string
	Label      *string
	Method     *string
	EnsureAuth *bool
	NoAppCode  *bool
	TokenKey   *string
	// contains filtered or unexported fields
}

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"`
	IsJwt            bool      `json:"isJwt"`
	// contains filtered or unexported fields
}

func (*UserToken) GetUserData added in v1.0.40

func (s *UserToken) GetUserData() any

func (UserToken) IsTokenExpired

func (s UserToken) IsTokenExpired() bool

func (*UserToken) SetUserData added in v1.0.40

func (s *UserToken) SetUserData(data any)

Jump to

Keyboard shortcuts

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