Documentation
¶
Index ¶
- Constants
- Variables
- func AbortScopedUnitWork(ctx context.Context)
- func AddAuthHandler[TKey comparable](h AuthHandler[TKey])
- func AddResultHandler(h ResultHandlerFunc)
- func AuthFunc[TKey comparable]() gin.HandlerFunc
- func AuthHandlerFunc(builder *ServerBuilder) gin.HandlerFunc
- func Configure(action ServerConfigureFunc)
- func CurrentTenant(c context.Context) *multi_tenancy.TenantInfo
- func EntityCreated(ctx *gin.Context, id string)
- func EntityNotFound(ctx *gin.Context, msg string)
- func EntityUpdated(ctx *gin.Context, count int)
- func Error(ctx *gin.Context, err *errx.HttpError)
- func ErrorMiddleware(c *gin.Context)
- func JSON(ctx *gin.Context, code int, v any)
- func JSONResult[T any](ctx *gin.Context, v T)
- func ManyEntitiesCreated(ctx *gin.Context, count int)
- func MultiTenancy() gin.HandlerFunc
- func NewHttpClient(hoptions *HttpClientOptions, middle ...func(*http.Request) (*url.URL, error)) *http.Client
- func NewJwtMiddleware(configure func(*jwt.GinJWTMiddleware)) (*jwt.GinJWTMiddleware, error)
- func NotFound(ctx *gin.Context)
- func Ok(ctx *gin.Context)
- func OnError(ctx context.Context, h ErrorHandFunc)
- func OptionalAuthHandlerFunc(builder *ServerBuilder) gin.HandlerFunc
- func Path(ctx *gin.Context, key string) string
- func PreConfigure(action ServerConfigureFunc)
- func Proxy(ctx *gin.Context, path string)
- func QueryBool(c *gin.Context, key string) bool
- func QueryID(ctx *gin.Context, key string) *primitive.ObjectID
- func QueryIDRequired(ctx *gin.Context, key string) primitive.ObjectID
- func QueryInt(ctx *gin.Context, key string, defaultValue int) int
- func QueryPage(ctx *gin.Context) (int, int)
- func QueryPageAndSort(ctx *gin.Context) *x.PageAndSort
- func QueryPageParams(ctx *gin.Context) *x.PageParam
- func QueryStrings(ctx *gin.Context, key string) []string
- func SuccessWithMessage(ctx *gin.Context, success bool, msg string)
- func UnitWorkMiddleware() gin.HandlerFunc
- func UseRestRoutes(cfg func(*jwt.GinJWTMiddleware))
- func WithScopedUnitwork(ctx context.Context) context.Context
- func WithUserContext[TKey comparable](c context.Context, user *CurrentUserInfo[TKey]) context.Context
- type AuthHandler
- type AuthHandlerContext
- type AuthOptions
- type AuthedEventData
- type CreateEntityResult
- type CreateManyEntitiesResult
- type CurrentUserInfo
- type DataFilterKey
- type DataResult
- type EntityUpdatedResult
- type ErrorHandFunc
- type ErrorHandlers
- type GinDataFilterProvider
- type HttpClientOptions
- type JWTBuilder
- type JwtClaims
- type RequestClient
- func (c *RequestClient) Get(url string, retry bool) ([]byte, error)
- func (c *RequestClient) GetObj(url string, result interface{}) error
- func (c *RequestClient) GetResponse(url string, retry bool) (*http.Response, error)
- func (c *RequestClient) GetString(url string) (string, error)
- func (c *RequestClient) Post(url string, body any) (*http.Response, error)
- func (c *RequestClient) PostByForm(url string, formData map[string]string) (*http.Response, error)
- type ResponseResult
- type ResultHandlerFunc
- type ResultHandlerOptions
- type Server
- type ServerBuilder
- func (b *ServerBuilder) Add(fun func(b *ServerBuilder)) *ServerBuilder
- func (b *ServerBuilder) Build() (*Server, error)
- func (b *ServerBuilder) Configure(action ServerConfigureFunc) *ServerBuilder
- func (b *ServerBuilder) PreConfigure(action ServerConfigureFunc) *ServerBuilder
- func (b *ServerBuilder) UseRestRoutes()
- type ServerConfigureFunc
- type ServerOptions
- type SuccessWithMessageResult
- type UnitWork
Constants ¶
View Source
const ( ClaimRole = "role" ClaimOrg = "org" ClaimUserId = "id" ClaimUserAddr = "addr" )
View Source
const ErrHandlersKey = "ErrorHandlers"
View Source
const UnitWorkKey = "UnitWorkKey"
Variables ¶
View Source
var ErrLoginFailed = errors.New("login failed")
Functions ¶
func AbortScopedUnitWork ¶
func AddAuthHandler ¶
func AddAuthHandler[TKey comparable](h AuthHandler[TKey])
AddAuthHandler adds a handler to the auth middleware.
func AddResultHandler ¶
func AddResultHandler(h ResultHandlerFunc)
func AuthFunc ¶
func AuthFunc[TKey comparable]() gin.HandlerFunc
func AuthHandlerFunc ¶
func AuthHandlerFunc(builder *ServerBuilder) gin.HandlerFunc
AuthHandlerFunc 获取认证中间件handler
func CurrentTenant ¶
func CurrentTenant(c context.Context) *multi_tenancy.TenantInfo
func EntityCreated ¶
func EntityNotFound ¶
func EntityUpdated ¶
func ErrorMiddleware ¶
ErrorMiddleware request panic error handler
func JSONResult ¶
func ManyEntitiesCreated ¶
func MultiTenancy ¶
func MultiTenancy() gin.HandlerFunc
func NewHttpClient ¶
func NewJwtMiddleware ¶
func NewJwtMiddleware(configure func(*jwt.GinJWTMiddleware)) (*jwt.GinJWTMiddleware, error)
func OnError ¶
func OnError(ctx context.Context, h ErrorHandFunc)
OnError 添加请求生命周期中出现错误时的处理方法。 注意: 该方法中不要使用panic
func OptionalAuthHandlerFunc ¶
func OptionalAuthHandlerFunc(builder *ServerBuilder) gin.HandlerFunc
OptionalAuthHandlerFunc 支持匿名和用户登录两种访问方式
func QueryPageAndSort ¶
func QueryPageAndSort(ctx *gin.Context) *x.PageAndSort
func UnitWorkMiddleware ¶
func UnitWorkMiddleware() gin.HandlerFunc
func UseRestRoutes ¶
func UseRestRoutes(cfg func(*jwt.GinJWTMiddleware))
func WithScopedUnitwork ¶
WithScopedUnitwork 使用默认的UnitWork,在当前请求周期中有效,自动提交事务
func WithUserContext ¶
func WithUserContext[TKey comparable](c context.Context, user *CurrentUserInfo[TKey]) context.Context
Types ¶
type AuthHandler ¶
type AuthHandler[TKey comparable] func(ctx *AuthHandlerContext[TKey]) error
type AuthHandlerContext ¶
type AuthHandlerContext[TKey comparable] struct { User *CurrentUserInfo[TKey] HasHandled bool // contains filtered or unexported fields }
func (*AuthHandlerContext[TKey]) Context ¶
func (ac *AuthHandlerContext[TKey]) Context() *gin.Context
type AuthOptions ¶
type AuthOptions[TKey comparable] struct { // contains filtered or unexported fields }
func (*AuthOptions[TKey]) AddHandler ¶
func (o *AuthOptions[TKey]) AddHandler(h AuthHandler[TKey])
type AuthedEventData ¶
type AuthedEventData[TKey comparable] struct { ID TKey `json:"id"` UserName string `json:"userName"` Address string `json:"address"` Avatar string `json:"avatar"` Data map[string]any `json:"data"` AuthType string // 验证类型 }
func NewAuthedEventData ¶
func NewAuthedEventData[TKey comparable](u *CurrentUserInfo[TKey]) *AuthedEventData[TKey]
type CreateEntityResult ¶
type CreateEntityResult struct {
ID string `json:"id"`
}
type CreateManyEntitiesResult ¶
type CreateManyEntitiesResult struct {
Count int `json:"count"`
}
type CurrentUserInfo ¶
type CurrentUserInfo[TKey comparable] struct { ID TKey UserName string Address string Avatar string AuthType string // 验证类型 Data map[string]any }
func CurrentUser ¶
func CurrentUser[TKey comparable](c context.Context) *CurrentUserInfo[TKey]
func (*CurrentUserInfo[TKey]) Authenticated ¶
func (u *CurrentUserInfo[TKey]) Authenticated() bool
func (*CurrentUserInfo[TKey]) Get ¶
func (u *CurrentUserInfo[TKey]) Get(key string) any
func (*CurrentUserInfo[TKey]) Set ¶
func (u *CurrentUserInfo[TKey]) Set(key string, value any)
type DataFilterKey ¶
type DataFilterKey = string
type DataResult ¶
type EntityUpdatedResult ¶
type EntityUpdatedResult struct {
Count int `json:"count"`
}
type ErrorHandFunc ¶
type ErrorHandlers ¶
type ErrorHandlers struct {
// contains filtered or unexported fields
}
func NewErrorHandlers ¶
func NewErrorHandlers() *ErrorHandlers
func (*ErrorHandlers) Add ¶
func (eh *ErrorHandlers) Add(h ErrorHandFunc)
type GinDataFilterProvider ¶
type GinDataFilterProvider struct { }
func (GinDataFilterProvider) DisableFilter ¶
func (GinDataFilterProvider) EnableFilter ¶
func (GinDataFilterProvider) EnableFilter(ctx context.Context, t reflect.Type)
func (GinDataFilterProvider) IsFilterDisabled ¶
type HttpClientOptions ¶
type HttpClientOptions struct {
ProxyURL string
}
type JWTBuilder ¶
type JWTBuilder struct {
// contains filtered or unexported fields
}
func AddJwt ¶
func AddJwt(builder *ServerBuilder, configure func(*jwt.GinJWTMiddleware)) *JWTBuilder
添加jwt
type RequestClient ¶
type RequestClient struct {
// contains filtered or unexported fields
}
func NewRequestClient ¶
func NewRequestClient(hoptions *HttpClientOptions) *RequestClient
func (*RequestClient) GetObj ¶
func (c *RequestClient) GetObj(url string, result interface{}) error
func (*RequestClient) GetResponse ¶
func (*RequestClient) PostByForm ¶
type ResponseResult ¶
type ResponseResult struct {
Value any `json:"value"`
}
func NewResponseResult ¶
func NewResponseResult(v any) *ResponseResult
type ResultHandlerFunc ¶
type ResultHandlerFunc func(ctx *gin.Context, v *ResponseResult)
type ResultHandlerOptions ¶
type ResultHandlerOptions struct {
// contains filtered or unexported fields
}
func (*ResultHandlerOptions) AddHandler ¶
func (opts *ResultHandlerOptions) AddHandler(h ResultHandlerFunc)
type Server ¶
type Server struct { G *gin.Engine Options *ServerOptions }
func (*Server) UseDefaultHandlers ¶
type ServerBuilder ¶
type ServerBuilder struct { Options *ServerOptions // 只在程序启动过程中进行操作,以保证协程安全 Items map[string]any // contains filtered or unexported fields }
func NewServerBuilder ¶
func NewServerBuilder() *ServerBuilder
func (*ServerBuilder) Add ¶
func (b *ServerBuilder) Add(fun func(b *ServerBuilder)) *ServerBuilder
func (*ServerBuilder) Build ¶
func (b *ServerBuilder) Build() (*Server, error)
func (*ServerBuilder) Configure ¶
func (b *ServerBuilder) Configure(action ServerConfigureFunc) *ServerBuilder
Configure 配置服务,该方法参数在App.Run中、gin.Run之前运行
func (*ServerBuilder) PreConfigure ¶
func (b *ServerBuilder) PreConfigure(action ServerConfigureFunc) *ServerBuilder
PreConfigure 配置服务,该方法参数在App.Run中、gin.Run之前运行
func (*ServerBuilder) UseRestRoutes ¶
func (b *ServerBuilder) UseRestRoutes()
type ServerConfigureFunc ¶
Click to show internal directories.
Click to hide internal directories.