route

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentDispositionHeaderKey         = "Content-Disposition"
	ContentDispositionHeaderValueFormat = `attachment; filename="%s"`
)

header相关

Variables

View Source
var (
	CheckerMockCheckProxyContext = func() (pctx inject.ProxyContext) {
		pctx = checkerMockCommonProxyContext
		pctx.MethodName = "Check"
		return
	}()
)
View Source
var (
	FilterMockFilterProxyContext = func() (pctx inject.ProxyContext) {
		pctx = filterMockCommonProxyContext
		pctx.MethodName = "Filter"
		return
	}()
)
View Source
var (
	NewerMockNewProxyContext = func() (pctx inject.ProxyContext) {
		pctx = newerMockCommonProxyContext
		pctx.MethodName = "New"
		return
	}()
)

Functions

func MakeCookie

func MakeCookie(userID int, co CookieOption) (cookie http.Cookie, err error)

MakeCookie 新建令牌

func RegisterProxyMethod added in v0.12.0

func RegisterProxyMethod(pctx inject.ProxyContext, cf inject.CtxFunc)

func SetResultVersion added in v0.7.0

func SetResultVersion(ver int)

Types

type AddResult

type AddResult struct {
	ID int `json:"id"` // 新纪录ID
}

AddResult 添加记录后的结果

type Checker

type Checker interface {
	Check(context.Context) error
}

Checker 检查接口

type CheckerMock added in v0.12.0

type CheckerMock struct {
	CheckFunc func(context.Context) error
}

func (*CheckerMock) Check added in v0.12.0

func (mockRecv *CheckerMock) Check(p0 context.Context) error

type Content

type Content struct {
	ContentLength int64             `json:"-"`
	ContentType   string            `json:"-"`
	ContentReader io.Reader         `json:"-"`
	ExtraHeaders  map[string]string `json:"-"`
}

Content 内容

func MakeContentFromBuffer

func MakeContentFromBuffer(filename string, buf *bytes.Buffer) Content

MakeContentFromBuffer 新建内容

func MakeContentFromBytes

func MakeContentFromBytes(filename string, content []byte) (Content, error)

type CookieOption

type CookieOption struct {
	SessionKey string
	JwtToken   *jwt.Token
}

type File

type File struct {
}

File 用来标志结构体的文件上传/下载属性

type Filter

type Filter interface {
	Filter() any
}

Filter 过滤器

type FilterMock added in v0.12.0

type FilterMock struct {
	FilterFunc func() any
}

func (*FilterMock) Filter added in v0.12.0

func (mockRecv *FilterMock) Filter() any

type Group

type Group struct {
}

Group 分组

type HandlerFunc

type HandlerFunc = func(context.Context, Param) (Result, error)

HandlerFunc 处理函数 使用别名,可以互相替换,但是不能添加方法 使用类型,不可以互相替换,需要转型,但是可以添加方法

type Limiter

type Limiter struct {
}

Limiter 限流器

type Method

type Method struct {
}

Method 方法

type Newer

type Newer interface {
	New() any
}

Newer 新建

type NewerMock added in v0.12.0

type NewerMock struct {
	NewFunc func() any
}

func (*NewerMock) New added in v0.12.0

func (mockRecv *NewerMock) New() any

type Option

type Option struct {
	SessionKey string
	JwtToken   *jwt.Token
}

type Param

type Param struct {
	// contains filtered or unexported fields
}

Param 参数

func (*Param) Parse

func (p *Param) Parse(ctx context.Context, v any) error

Parse 解析

func (*Param) ParseMultipartForm

func (p *Param) ParseMultipartForm(maxFileSize int64, v any) (map[string][]byte, error)

ParseMultipartForm 解析内容

type RegisterOption

type RegisterOption struct {
	InfluxAPIWriter api.WriteAPI
	ReqTimeout      time.Duration
}

type Result

type Result struct {
	utilerrors.Error

	Data any `json:"data"` // 正常返回时的数据

	// 给登陆接口使用
	CookieAfterLogin int `json:"-"` // 登陆时需要设置登陆态的用户信息

	// 时间戳
	Timestamp int64 `json:"timestamp"`

	// 请求ID,在请求到来时生成,处理过程传递,返回时一并返回
	RequestID string `json:"requestID"` // uuid

	// 下载内容时使用
	Content
}

Result 结果

func (Result) MarshalJSON added in v0.7.0

func (r Result) MarshalJSON() ([]byte, error)

func (*Result) PresentData

func (r *Result) PresentData(v any) error

PresentData 用具体结构体展现数据

func (*Result) ToResult1 added in v0.7.0

func (r *Result) ToResult1() Result1

type Result1 added in v0.7.0

type Result1 struct {
	Header ResultCode `json:"header"`
	Data   any        `json:"data"` // 可以是对象或数组
}

type ResultCode added in v0.7.0

type ResultCode struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Count   int    `json:"count"`
}

type Router

type Router struct {
	*gin.Engine
	// contains filtered or unexported fields
}

Router 路由

func NewRouter

func NewRouter(opt Option) *Router

NewRouter 新建路由

func (*Router) Register

func (r *Router) Register(v any, opt RegisterOption)

Register 注册结构体 结构体名字作为路径的第一部分,路径后面部分由可导出方法名映射来

Jump to

Keyboard shortcuts

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