ctl

package
v1.3.28 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

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

type ControllerContext

type ControllerContext interface {
	// CheckToken 检查token是否有效 该方法出错会panic 并被panic handler拦截
	CheckToken(Token)
	// GetToken 获取token包含的内容
	GetToken() Payload
	// GetHeader 获取header
	GetHeader(key string) string
	// SetHeader 设置header
	SetHeader(key, val string)
	// GetRequestInfo 获取请求方法,和链接地址
	GetRequestInfo() (method, url string)
	// Bind 绑定参数 该方法出错会panic 并被panic handler拦截
	Bind(params any, bindings ...BindOption)
	// SetContext 设置web框架的上下文对象
	SetContext(context.Context) ControllerContext
	// GetContext 获得上下文
	GetContext() context.Context
	// 设置加密方法
	SetEncryption(func(ctx ControllerContext, data any) (any, error))
	// 成功返回统一接口
	Success(data any) *Result
}

ControllerContext 请求体接口

type GinControllerContext

type GinControllerContext struct {
	*gin.Context

	Encryption func(ctx ControllerContext, data any) (any, error)
	// 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) GetRequestInfo added in v1.3.28

func (c *GinControllerContext) GetRequestInfo() (method, url string)

func (*GinControllerContext) GetToken

func (c *GinControllerContext) GetToken() Payload

func (GinControllerContext) SetContext

func (*GinControllerContext) SetEncryption added in v1.3.28

func (c *GinControllerContext) SetEncryption(f func(ctx ControllerContext, data any) (any, error))

func (*GinControllerContext) SetHeader

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

func (*GinControllerContext) Success added in v1.3.28

func (c *GinControllerContext) Success(data any) *Result

type GinFormMultipartFileBinding added in v1.3.2

type GinFormMultipartFileBinding struct {
}

func (GinFormMultipartFileBinding) Bind added in v1.3.2

func (GinFormMultipartFileBinding) Name added in v1.3.2

type GinRegister added in v1.3.2

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

type GinRegisterList added in v1.3.2

type GinRegisterList []GinRegister

func (GinRegisterList) LoadRoute added in v1.3.2

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 added in v1.3.2

type Payload interface {
	Clone() Payload
	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(args ...any) *Result

Err 错误返回

func (*Result) String

func (r *Result) String(data string) *Result

String 成功返回字符串

func (*Result) SuccessIn

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

SuccessIn 成功拷贝回复

type Token added in v1.3.2

type Token interface {
	Clone() Token
	Sign() error
	Verify(ctx ControllerContext) error //验证
	GetPayLoad() Payload
	GetConfig() config.Token
}

Jump to

Keyboard shortcuts

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