ctl

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const JwtPayloadKey = "JWT_PAYLOAD"

Variables

View Source
var (
	// ErrEmptyQueryToken can be thrown if authing with URL Query, the query token variable is empty
	ErrEmptyQueryToken = errors.New("query token is empty")

	// ErrEmptyCookieToken can be thrown if authing with a cookie, the token cokie is empty
	ErrEmptyCookieToken = errors.New("cookie token is empty")

	// ErrEmptyAuthHeader can be thrown if authing with a HTTP header, the Auth header needs to be set
	ErrEmptyAuthHeader = errors.New("auth header is empty")

	// ErrInvalidAuthHeader indicates auth header is invalid, could for example have the wrong Realm name
	ErrInvalidAuthHeader = errors.New("auth header is invalid")
)

Functions

func Copy

func Copy[T any](to T, from any, opts ...copier.Option) T

Types

type BindOption

type BindOption uint8
const (
	Json BindOption
	Xml
	Yaml
	Form
	Query
	Uri
	File
)

type ControllerContext

type ControllerContext interface {
	// CheckToken 检查token是否有效 该方法出错会panic 并被panic handler拦截
	CheckToken(Token)
	// GetPayload 获取token中包含的内容
	GetPayload() Payload
	// GetHeader 获取header
	GetHeader(key string) string
	// SetHeader 设置header
	SetHeader(key, val string)
	// Bind 绑定参数 该方法出错会panic 并被panic handler拦截
	Bind(params any, bindings ...BindOption)
	// SetContext 设置web框架的上下文对象
	SetContext(context.Context) ControllerContext
	// GetContext 获得上下文
	GetContext() context.Context
}

ControllerContext 请求体接口

type GinControllerContext

type GinControllerContext struct {
	*gin.Context
	// contains filtered or unexported fields
}

GinControllerContext gin 请求体接口实现

func NewGinContext

func NewGinContext(conf *config.Web) *GinControllerContext

func (*GinControllerContext) Bind

func (c *GinControllerContext) Bind(params any, opts ...BindOption)

func (*GinControllerContext) CheckToken

func (c *GinControllerContext) CheckToken(tk Token)

func (*GinControllerContext) GetContext

func (c *GinControllerContext) GetContext() context.Context

func (*GinControllerContext) GetPayload added in v1.0.9

func (c *GinControllerContext) GetPayload() Payload

func (GinControllerContext) SetContext

func (*GinControllerContext) SetHeader

func (c *GinControllerContext) SetHeader(key, val string)

type GinFormMultipartFileBinding

type GinFormMultipartFileBinding struct {
}

func (GinFormMultipartFileBinding) Bind

func (GinFormMultipartFileBinding) Name

type GinRegister

type GinRegister struct {
	Method  string
	Path    string
	Handles []gin.HandlerFunc
}

type GinRegisterList

type GinRegisterList []GinRegister

func (GinRegisterList) LoadRoute

func (r GinRegisterList) LoadRoute(g *gin.Engine)

加载路由

type Paging

type Paging struct {
	Page  int64 `form:"page"`
	Limit int64 `form:"limit"`
	Order int32 `form:"order"`
}

type Payload

type Payload interface {
	ToBytes() []byte
	FromBytes(from []byte) error
	Expire() int64
}

type Result

type Result struct {
	Code      int    `json:"code"`      //状态码 200正常 500错误
	Msg       string `json:"msg"`       //错误消息
	Data      any    `json:"data"`      //返回数据
	RequestId string `json:"requestId"` //请求编号链路中来
	// contains filtered or unexported fields
}

Result 统一返回体

func (*Result) Bytes

func (r *Result) Bytes(data []byte) *Result

Bytes 成功返回字节数组

func (*Result) Err

func (r *Result) Err(err error, msg ...string) *Result

Err 错误返回

func (*Result) Message added in v1.0.15

func (r *Result) Message(msg string) *Result

Message 成功返回提示信息

func (*Result) Success

func (r *Result) Success(data any) *Result

Success 成功返回

func (*Result) SuccessIn

func (r *Result) SuccessIn(to any, from any) *Result

SuccessIn 成功拷贝回复

type Token

type Token interface {
	Clone() Token
	Sign(payload Payload) (string, error)
	Verify(token string) error
	GetPayLoad(token string) (Payload, error)
	GetConfig() config.Token
}

Jump to

Keyboard shortcuts

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