api

package
v0.0.0-...-a88cfdc Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleFunc

func HandleFunc(pattern string, f func(ctx *Context) []ResponseOption)

Types

type AppContext

type AppContext struct {
	Config      *config.AppConfig
	Logger      *zap.Logger
	RedisClient *redis.Client
	Db          *ent.Client
	Consumer    *redisqueue.Consumer
	Producer    *redisqueue.Producer
}

func NewAppContext

func NewAppContext(config *config.AppConfig, logger *zap.Logger, redisClient *redis.Client, db *ent.Client, consumer *redisqueue.Consumer, producer *redisqueue.Producer) *AppContext

func (AppContext) Deadline

func (a AppContext) Deadline() (deadline time.Time, ok bool)

func (AppContext) Done

func (a AppContext) Done() <-chan struct{}

func (AppContext) Err

func (a AppContext) Err() error

func (AppContext) Value

func (a AppContext) Value(key any) any

type Context

type Context struct {
	*AppContext
	Writer http.ResponseWriter
	Req    *http.Request
}

func (*Context) Deadline

func (ctx *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (ctx *Context) Done() <-chan struct{}

func (*Context) Err

func (ctx *Context) Err() error

func (*Context) GetBody

func (ctx *Context) GetBody() ([]byte, error)

func (*Context) Value

func (ctx *Context) Value(key any) any

func (*Context) WrapperGinHandleFunc

func (ctx *Context) WrapperGinHandleFunc(f func(ctx *Context) ResponseOptions) gin.HandlerFunc

type Response

type Response struct {
	HttpCode int `json:"-"`
	ResponseEntry
}

func NewResponse

func NewResponse(opts []ResponseOption) *Response

type ResponseData

type ResponseData interface{}

type ResponseEntry

type ResponseEntry struct {
	// 内部状态码
	Status int `json:"status"`
	// 响应信息
	Message string `json:"message"`
	// 实际的返回响应
	Data interface{} `json:"data,omitempty"`
	// 响应时间戳
	Timestamp int64 `json:"timestamp"`
}

type ResponseOption

type ResponseOption interface {
	// contains filtered or unexported methods
}

func Data

func Data(data ResponseData) ResponseOption

func Error

func Error(code int, message string) []ResponseOption

func ErrorWithOpts

func ErrorWithOpts(httpCode int, opts ...ResponseOption) []ResponseOption

func HttpCode

func HttpCode(code int) ResponseOption

func Message

func Message(message string) ResponseOption

func New

func New(code, status int, message string, data ResponseData) []ResponseOption

func Ok

func Ok(data ResponseData) []ResponseOption

func Status

func Status(status int) ResponseOption

type ResponseOptions

type ResponseOptions = []ResponseOption

Jump to

Keyboard shortcuts

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