api

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RouterRoot   = "root"
	RouterPrefix = "prefix"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

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

func New

func New(opts ...Option) *Api

func NewWithEngine added in v0.3.0

func NewWithEngine(server *http.Server, engine *gin.Engine, opts ...Option) *Api

func (*Api) ChooseRouter added in v0.2.2

func (api *Api) ChooseRouter(routerType string, version string) Router

ChooseRouter 选择Router 参数: - routerType: 路由类型,有两种

  • api.RouterRoot: 根路由
  • api.RouterPrefix: 带url前缀的路由

- version: 版本,用于获取基于上面两中路由够造的带有版本号的路由,传空字符串则选定上面两种路由本身 返回值: - 选择的Router

func (*Api) Finish

func (api *Api) Finish() error

Finish 终止Api 参数: 无 返回值: - 错误

func (*Api) Options

func (api *Api) Options() Options

Options 获取Api的选项 参数: 无 返回值: - Api的选项

func (*Api) PrefixRouter

func (api *Api) PrefixRouter() Router

PrefixRouter 获取Api的前缀路由 参数: 无 返回值: - Api的前缀路由

func (*Api) RootRouter

func (api *Api) RootRouter() Router

RootRouter 获取Api的根路由 参数: 无 返回值: - Api的根路由

func (*Api) Start

func (api *Api) Start() error

Start 运行Api 参数: 无 返回值: - 错误

type BytesBody added in v0.10.12

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

func (*BytesBody) Bytes added in v0.10.12

func (bytesBody *BytesBody) Bytes() []byte

Bytes 获取字节body的内容 参数: 无 返回值: - 字节body的内容

func (*BytesBody) Marshal added in v0.10.12

func (bytesBody *BytesBody) Marshal(input any) error

Marshal 将input Marshal到字节body 参数: - input: 输入,一般为结构或map[string]any 返回值: - 错误

func (*BytesBody) Reload added in v0.11.12

func (bytesBody *BytesBody) Reload() error

Reload 从Context重新加载BytesBody 参数: 无 返回值: - 错误

func (*BytesBody) Set added in v0.10.12

func (bytesBody *BytesBody) Set(body []byte)

Set 设置字节body 参数: - body: 字节body的内容 返回值: 无

func (*BytesBody) Unmarshal added in v0.10.12

func (bytesBody *BytesBody) Unmarshal(output any) error

Unmarshal 将字节body的内容Unmarshal到output 参数: - output: 输出,一般为结构指针或map[string]any指针 返回值: - 错误

type Context

type Context struct {
	*gin.Context
}

func (*Context) GetBytesBody added in v0.6.0

func (c *Context) GetBytesBody() (*BytesBody, error)

GetBytesBody 获取上下文中的字节Body 参数: 无 返回值: - 上下文中的字节Body - 错误

func (*Context) GetFileHeaderBytes

func (c *Context) GetFileHeaderBytes(fileHeader *multipart.FileHeader) (string, []byte, error)

GetFileHeaderBytes 获取Multipart中传递的文件名和文件内容 参数: - fileHeader: Multipart的文件头 返回值: - 文件名 - 文件字节 - 错误

func (*Context) GetHeader added in v0.10.1

func (c *Context) GetHeader() *Header

GetHeader 获取上下文中的Header 参数: 无 返回值: - 上下文中的Header

func (*Context) GetJsonBody added in v0.6.0

func (c *Context) GetJsonBody() (*JsonBody, error)

GetJsonBody 获取上下文中的JsonBody 参数: 无 返回值: - 上下文中的JsonBody - 错误

func (*Context) GetOriginPathParams added in v0.11.3

func (c *Context) GetOriginPathParams() map[string]string

GetOriginPathParams 获取上下文中的原始路径参数 参数: 无 返回值: - 上下文中的原始路径参数

func (*Context) GetOriginQueryParams added in v0.11.3

func (c *Context) GetOriginQueryParams() map[string]string

GetOriginQueryParams 获取上下文中的原始查询参数 参数: 无 返回值: - 上下文中的原始查询参数

func (*Context) GetPathParams added in v0.6.0

func (c *Context) GetPathParams() *PathPrams

GetPathParams 获取上下文中的路径参数 参数: 无 返回值: - 上下文中的路径参数 - 错误

func (*Context) GetQueryParams added in v0.6.0

func (c *Context) GetQueryParams() *QueryPrams

GetQueryParams 获取上下文中的查询参数 参数: 无 返回值: - 上下文中的查询参数 - 错误

func (*Context) GetTenantInfo added in v0.4.0

func (c *Context) GetTenantInfo() TenantInfo

func (*Context) GetUserInfo added in v0.4.0

func (c *Context) GetUserInfo() UserInfo

func (*Context) ReadOriginBody added in v0.11.3

func (c *Context) ReadOriginBody() ([]byte, error)

ReadOriginBody 获取上下文中的原始字节Body 参数: 无 返回值: - 上下文中的原始字节Body - 错误

func (*Context) ReadOriginHeader added in v0.11.12

func (c *Context) ReadOriginHeader() map[string]string

func (*Context) SetTenantInfo added in v0.8.0

func (c *Context) SetTenantInfo(tenantInfo TenantInfo)

func (*Context) SetUserInfo added in v0.8.0

func (c *Context) SetUserInfo(userInfo UserInfo)

type Handler

type Handler func(c *Context)

Handler 请求处理函数

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

func (*Header) Get added in v0.10.1

func (header *Header) Get(key string) string

Get 获取Header对应键的值 参数: - key: Header的键 返回值: - Header对应键的值

func (*Header) Map added in v0.10.1

func (header *Header) Map() map[string]string

Map 获取Header的map表示 参数: 无 返回值: - Header的map表示

func (*Header) Reload added in v0.11.12

func (header *Header) Reload()

Reload 从Context重新加载Header 参数: 无 返回值: 无

func (*Header) Set added in v0.10.1

func (header *Header) Set(key string, value string)

Set 设置Header 参数: - key: Header的键 - value: Header对应键的值 返回值: 无

type JsonBody added in v0.6.0

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

func (*JsonBody) Bytes added in v0.6.0

func (jsonBody *JsonBody) Bytes() ([]byte, error)

Bytes 获取JsonBody的内容 参数: 无 返回值: - JsonBody的内容

func (*JsonBody) Delete added in v0.6.0

func (jsonBody *JsonBody) Delete(key string)

Delete 删除JsonBody键对应的值 参数: - key: JsonBody的键 返回值: 无

func (*JsonBody) Get added in v0.6.0

func (jsonBody *JsonBody) Get(key string) any

Get 获取JsonBody对应键的值 参数: - key: JsonBody的键 返回值: - JsonBody对应键的值

func (*JsonBody) Map added in v0.6.0

func (jsonBody *JsonBody) Map() map[string]any

Map 获取JsonBody的map表示 参数: 无 返回值: - JsonBody的map表示

func (*JsonBody) Reload added in v0.11.12

func (jsonBody *JsonBody) Reload() error

Reload 从Context重新加载JsonBody 参数: 无 返回值: - 错误

func (*JsonBody) Set added in v0.6.0

func (jsonBody *JsonBody) Set(key string, value any)

Set 设置JsonBody键对应的值 参数: - key: JsonBody的键 - value: JsonBody对应键的值 返回值: 无

func (*JsonBody) SetMap added in v0.11.15

func (jsonBody *JsonBody) SetMap(mapBody map[string]any)

SetMap 使用map设置JsonBody 参数: - mapBody: map表示的body 返回值: 无

func (*JsonBody) Unmarshal added in v0.6.0

func (jsonBody *JsonBody) Unmarshal(output any) error

Unmarshal 将JsonBody的内容Unmarshal到output 参数: - output: 输出,一般为结构指针或map[string]any指针 返回值: - 错误

type Option

type Option func(options *Options)

func WithLogSkipPaths added in v0.10.12

func WithLogSkipPaths(logSkipPaths ...string) Option

WithLogSkipPaths 设置日志跳过的打印路径

func WithPort

func WithPort(port string) Option

WithPort 设置端口

func WithUrlPrefix

func WithUrlPrefix(urlPrefix string) Option

WithUrlPrefix 设置URL前缀

type Options

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

func (Options) GetPort

func (options Options) GetPort() string

func (Options) GetUrlPrefix

func (options Options) GetUrlPrefix() string

type PathPrams added in v0.6.0

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

func (*PathPrams) Delete added in v0.6.0

func (pathParams *PathPrams) Delete(key string)

Delete 删除JsonBody键对应的值 参数: - key: JsonBody的键 返回值: 无

func (*PathPrams) Get added in v0.6.0

func (pathParams *PathPrams) Get(key string) string

Get 获取路径参数对应键的值 参数: - key: 路径参数的键 返回值: - 路径参数对应键的值

func (*PathPrams) Map added in v0.6.0

func (pathParams *PathPrams) Map() map[string]string

Map 获取路径参数的map表示 参数: 无 返回值: - 路径参数的map表示

func (*PathPrams) Reload added in v0.11.12

func (pathParams *PathPrams) Reload()

Reload 从Context重新加载QueryParams 参数: 无 返回值: 无

func (*PathPrams) Set added in v0.6.0

func (pathParams *PathPrams) Set(key string, value string)

Set 设置路径参数 参数: - key: 路径参数的键 - value: 路径参数对应键的值 返回值: 无

func (*PathPrams) SetMap added in v0.11.15

func (pathParams *PathPrams) SetMap(mapPathParams map[string]string)

SetMap 使用map设置路径参数 参数: - mapPathParams: map表示的路径参数 返回值: 无

type PrefixRouter

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

func (*PrefixRouter) AddMiddlewares

func (r *PrefixRouter) AddMiddlewares(middlewares ...Handler) Router

func (*PrefixRouter) AddRoute

func (r *PrefixRouter) AddRoute(method string, relativePath string, handlers ...Handler) Router

func (*PrefixRouter) BasePath

func (r *PrefixRouter) BasePath() string

func (*PrefixRouter) RegisterVersionedRouter

func (r *PrefixRouter) RegisterVersionedRouter(version string, middlewares ...Handler) Router

func (*PrefixRouter) Static

func (r *PrefixRouter) Static(relativePath string, root string)

func (*PrefixRouter) StaticFile

func (r *PrefixRouter) StaticFile(relativePath string, filepath string)

func (*PrefixRouter) VersionedRouter

func (r *PrefixRouter) VersionedRouter(version string) Router

type QueryPrams added in v0.6.0

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

func (*QueryPrams) Delete added in v0.6.0

func (queryParams *QueryPrams) Delete(key string)

Delete 删除JsonBody键对应的值 参数: - key: JsonBody的键 返回值: 无

func (*QueryPrams) Get added in v0.6.0

func (queryParams *QueryPrams) Get(key string) string

Get 获取查询参数对应键的值 参数: - key: 查询参数的键 返回值: - 查询参数对应键的值

func (*QueryPrams) Map added in v0.6.0

func (queryParams *QueryPrams) Map() map[string]string

Map 获取查询参数的map表示 参数: 无 返回值: - 查询参数的map表示

func (*QueryPrams) Reload added in v0.11.12

func (queryParams *QueryPrams) Reload()

Reload 从Context重新加载QueryParams 参数: 无 返回值: 无

func (*QueryPrams) Set added in v0.6.0

func (queryParams *QueryPrams) Set(key string, value string)

Set 设置查询参数 参数: - key: 查询参数的键 - value: 查询参数对应键的值 返回值: 无

func (*QueryPrams) SetMap added in v0.11.15

func (queryParams *QueryPrams) SetMap(mapQueryParams map[string]string)

SetMap 使用map设置查询参数 参数: - mapQueryParams: map表示的查询参数 返回值: 无

type RootRouter

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

func (*RootRouter) AddMiddlewares

func (r *RootRouter) AddMiddlewares(middlewares ...Handler) Router

func (*RootRouter) AddRoute

func (r *RootRouter) AddRoute(method string, relativePath string, handlers ...Handler) Router

func (*RootRouter) BasePath

func (r *RootRouter) BasePath() string

func (*RootRouter) RegisterVersionedRouter

func (r *RootRouter) RegisterVersionedRouter(version string, middlewares ...Handler) Router

func (*RootRouter) ServerHttp

func (r *RootRouter) ServerHttp(w http.ResponseWriter, req *http.Request)

func (*RootRouter) Static

func (r *RootRouter) Static(relativePath string, root string)

func (*RootRouter) StaticFile

func (r *RootRouter) StaticFile(relativePath string, filepath string)

func (*RootRouter) VersionedRouter

func (r *RootRouter) VersionedRouter(version string) Router

type Router

type Router interface {
	// AddMiddlewares 添加中间件
	AddMiddlewares(middlewares ...Handler) Router

	// RegisterVersionedRouter 注册版本路由
	RegisterVersionedRouter(version string, middlewares ...Handler) Router

	// VersionedRouter 获取版本路由
	VersionedRouter(version string) Router

	// AddRoute 添加路由路径
	AddRoute(method string, relativePath string, handlers ...Handler) Router

	// Static 静态路由(指向目录)
	Static(relativePath string, root string)

	// StaticFile 静态路由(指向文件)
	StaticFile(relativePath string, filepath string)

	// BasePath 路由的基础路径,即去掉http://ip:port之后的URL部分(不包括AddRoute的RelativePath)
	BasePath() string
}

Router 路由接口

type TenantInfo added in v0.4.0

type TenantInfo interface {
	GetID() string
	GetName() string
}

type UserInfo added in v0.4.0

type UserInfo interface {
	GetID() string
	GetUserName() string
	GetName() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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