rest

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UseEncrypted = false
	AesKey       = "gscafflod-rest"
)

加密通信使用, 一般 app 中需要. 本工具尚未支持.

Functions

func NewGinRouter

func NewGinRouter() *gin.Engine

Types

type HTTPBundle

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

func New

func New(router http.Handler, opts ...Option) *HTTPBundle

func (*HTTPBundle) GetName

func (bundle *HTTPBundle) GetName() string

func (*HTTPBundle) LoadDefault

func (bundle *HTTPBundle) LoadDefault()

func (*HTTPBundle) Run

func (bundle *HTTPBundle) Run(ctx context.Context)

func (*HTTPBundle) Stop

func (bundle *HTTPBundle) Stop(ctx context.Context)

type IDRequest

type IDRequest struct {
	ID int64 `uri:"id" form:"id" json:"id" binding:"required"`
}

IDRequest 简单封装一个只有 id 参数的请求体.

func (*IDRequest) Validate

func (req *IDRequest) Validate() error

type IDRequestString

type IDRequestString struct {
	ID string `json:"id"`
}

func (*IDRequestString) Validate

func (req *IDRequestString) Validate() error

type IDRequestUint

type IDRequestUint struct {
	ID uint64 `json:"id"`
}

func (*IDRequestUint) Validate

func (req *IDRequestUint) Validate() error

type Option

type Option func(bundle *HTTPBundle)

func OptionPort

func OptionPort(port int) Option

func OptionReadTimeout

func OptionReadTimeout(t time.Duration) Option

func OptionTimeout

func OptionTimeout(t time.Duration) Option

func OptionWriteTimeout

func OptionWriteTimeout(t time.Duration) Option

type PageBaseRequest

type PageBaseRequest struct {
	Limit   int    `form:"limit" json:"limit"`
	Offset  int    `form:"offset" json:"offset"`
	LastID  int64  `form:"last_id" json:"last_id"`
	Order   string `form:"order" json:"order"`       // default desc.
	OrderBy string `form:"order_by" json:"order_by"` // default id
}

func (*PageBaseRequest) LoadDefault

func (req *PageBaseRequest) LoadDefault()

type PageBaseResponse

type PageBaseResponse struct {
	Total   int         `json:"total"`
	Records interface{} `json:"records"`
	LastID  interface{} `json:"last_id"`
}

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"msg"`
	Data    interface{} `json:"data"`
}

resp.code 表示业务状态, 用于进一步细分 http.code. http.code 表示接口整体状态, 如 404 not found. resp.code 进一步区分业务状态, 如 20001 订单已退款, 表示接口正常但业务自身逻辑失败.

func FailResponse

func FailResponse(code int, msg string) *Response

请求成功的响应

func SucResponse

func SucResponse(data interface{}) *Response

请求成功的响应

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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