web

package
v1.0.38 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeOctetStream = "application/octet-stream"
	TypeForm        = "application/x-www-form-urlencoded"
	TypeJson        = "application/json"
	TypeXml         = "application/xml"
	TypeJpg         = "image/jpeg"
	TypePng         = "image/png"
)

Variables

This section is empty.

Functions

func CheckSign

func CheckSign(sign, appid, path, ts string) (ok bool)

func ClientIP added in v1.0.25

func ClientIP(r *http.Request, rHeader http.Header) string

func File

func File(c *gin.Context, filePath, fileName string)

func GinProxy added in v1.0.25

func GinProxy[Rsp any](c *gin.Context, method, host, uri string) (rspParam Rsp, err error)

GinProxy gin request proxy and get rsp

func GinPureProxy added in v1.0.25

func GinPureProxy(c *gin.Context, method, host, uri string)

GinPureProxy gin request proxy

func JSON

func JSON(c *gin.Context, data any, err error)

func ReadRequestBody

func ReadRequestBody(req *http.Request) (bs []byte, err error)

func Redirect

func Redirect(c *gin.Context, location string)

func VerifySign

func VerifySign(c *gin.Context)

VerifySign 验证Sign,签名规则,base64(md5(appid+path+ts))

Types

type AccessConfig added in v1.0.26

type AccessConfig struct {
	AppName      string     `json:"app_name" yaml:"app_name" toml:"app_name"`                   // app name,记录日志标识
	OutputType   OutputType `json:"output_type" yaml:"output_type" toml:"output_type"`          // 日志输出类型:stdout、file、sls
	FilePath     string     `json:"file_path" yaml:"file_path" toml:"file_path"`                // 日志输出文件路径(输出类型为file时有效)
	SlsAccessKey string     `json:"sls_access_key" yaml:"sls_access_key" toml:"sls_access_key"` // 日志输出到阿里云SLS时的access_key
	SlsSecretKey string     `json:"sls_secret_key" yaml:"sls_secret_key" toml:"sls_secret_key"` // 日志输出到阿里云SLS时的secret_key
	SlsEndpoint  string     `json:"sls_endpoint" yaml:"sls_endpoint" toml:"sls_endpoint"`       // 日志输出到阿里云SLS时的endpoint
	SlsProject   string     `json:"sls_project" yaml:"sls_project" toml:"sls_project"`          // 日志输出到阿里云SLS时的project
	SlsLogStore  string     `json:"sls_log_store" yaml:"sls_log_store" toml:"sls_log_store"`    // 日志输出到阿里云SLS时的log_store
}

type CommonRsp

type CommonRsp struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

type Config

type Config struct {
	Addr         string         `json:"addr" yaml:"addr" toml:"addr"`                            // addr, default :2233
	ReadTimeout  xtime.Duration `json:"read_timeout" yaml:"read_timeout" toml:"read_timeout"`    // read_timeout, default 60s
	WriteTimeout xtime.Duration `json:"write_timeout" yaml:"write_timeout" toml:"write_timeout"` // write_timeout, default 60s
	Debug        bool           `json:"debug" yaml:"debug" toml:"debug"`                         // is show log
	Limiter      *limit.Config  `json:"limiter" yaml:"limiter" toml:"limiter"`                   // interface limit
	Trace        *trace.Config  `json:"trace" yaml:"trace" toml:"trace"`                         // jaeger trace config
}

type GinEngine

type GinEngine struct {
	Gin    *gin.Engine
	Tracer *trace.Tracer

	IgnoreReleaseLog bool
	// contains filtered or unexported fields
}

func InitGin

func InitGin(c *Config) *GinEngine

func (*GinEngine) AccessLog added in v1.0.26

func (g *GinEngine) AccessLog(ac *AccessConfig) gin.HandlerFunc

AccessLog middleware for request and response body

func (*GinEngine) AddExitHook added in v1.0.29

func (g *GinEngine) AddExitHook(hooks ...HookFunc) *GinEngine

添加 GinServer 进程退出时钩子函数

func (*GinEngine) AddShutdownHook added in v1.0.30

func (g *GinEngine) AddShutdownHook(hooks ...HookFunc) *GinEngine

添加 GinServer 服务关闭时的钩子函数

func (*GinEngine) CORS

func (g *GinEngine) CORS() gin.HandlerFunc

CORS gin middleware cors

func (*GinEngine) Close

func (g *GinEngine) Close()

func (*GinEngine) Logger added in v1.0.20

func (g *GinEngine) Logger(ignoreRelease bool) gin.HandlerFunc

Logger

func (*GinEngine) Recovery

func (g *GinEngine) Recovery() gin.HandlerFunc

Recovery gin middleware recovery

func (*GinEngine) Start

func (g *GinEngine) Start()

type HookFunc added in v1.0.29

type HookFunc func(c context.Context)

type HttpRsp added in v1.0.25

type HttpRsp[V any] struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    V      `json:"data,omitempty"`
}

type OutputType added in v1.0.26

type OutputType string
const (
	OutputStdout OutputType = "stdout"
	OutputSLS    OutputType = "sls"
	OutputFile   OutputType = "file"
)

type Pager

type Pager struct {
	PageNo   int `json:"page_no"`
	PageSize int `json:"page_size"`
}

func (Pager) Apply

func (p Pager) Apply(total int64, data any) any

type RecoverInfo

type RecoverInfo struct {
	Time        string `json:"time"`
	RequestURI  string `json:"request_uri"`
	Body        string `json:"body"`
	RequestInfo string `json:"request_info"`
	Err         any    `json:"error"`
	Stack       string `json:"stack"`
}

Jump to

Keyboard shortcuts

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