http

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func AppName

func AppName(name string) utils.OptionFunc[useOption]

func Construct

func Construct(ctx context.Context, conf Conf, opts ...utils.OptionExtender) func()

func ContentZeroCopy

func ContentZeroCopy(fn getContentFn, opts ...utils.OptionExtender) func(c *gin.Context)

ContentZeroCopy zero copy gin handler wrapper for seeker

func Err

func Err(c *gin.Context, code Errcode, opts ...utils.OptionExtender) error

Err customized message

func ErrCtx

func ErrCtx(ctx context.Context, code Errcode, opts ...utils.OptionExtender) error

ErrCtx customized message

func Error added in v1.0.0

func Error[T constraint.Integer](c *gin.Context, appName string, code T, data any, page, count int, msg string)

func HandleAfter

func HandleAfter(aftersHandlers ...routerHandler) utils.OptionFunc[routerOption]

func HandleBefore

func HandleBefore(beforeHandlers ...routerHandler) utils.OptionFunc[routerOption]

func Langs

func Langs(c *gin.Context) utils.OptionFunc[errOption]

func Localizable

func Localizable(opts ...utils.OptionExtender) i18n.Localizable[Errcode]

func Msg

func Msg(msg string) utils.OptionFunc[errOption]

func Param

func Param(param map[string]any) utils.OptionFunc[errOption]

func ParseFromBody

func ParseFromBody() utils.OptionFunc[routerOption]

func ParseFromQuery

func ParseFromQuery() utils.OptionFunc[routerOption]

func StaticFileZeroCopy

func StaticFileZeroCopy(filename string) func(c *gin.Context)

StaticFileZeroCopy zero copy gin handler wrapper for static file

func Success added in v1.0.0

func Success(c *gin.Context, appName string, data any, page, count int, msg string)

Types

type Conf

type Conf struct {
	Port            int         `yaml:"port" json:"port" toml:"port" default:"80"`
	TLS             bool        `yaml:"tls" json:"tls" toml:"tls" default:"false"`
	Cert            string      `yaml:"cert" json:"cert" toml:"cert"`
	Key             string      `yaml:"key" json:"key" toml:"key"`
	NextProtos      []string    `yaml:"next_protos" json:"next_protos" toml:"next_protos" default:"[http/1.1]"` // h2, http/1.1 is ok
	SuccessCode     int         `yaml:"success_code" json:"success_code" toml:"success_code"`
	Pprof           bool        `yaml:"pprof" json:"pprof" toml:"pprof"`
	XSSWhiteURLList []string    `yaml:"xss_white_url_list" json:"xss_white_url_list" toml:"xss_white_url_list" default:"[]"`
	ColorfulConsole bool        `yaml:"colorful_console" json:"colorful_console" toml:"colorful_console" default:"false"`
	ReadTimeout     string      `yaml:"read_timeout" json:"read_timeout" toml:"read_timeout" default:"10s"`
	WriteTimeout    string      `yaml:"write_timeout" json:"write_timeout" toml:"write_timeout" default:"10s"`
	Asynq           []asynqConf `yaml:"asynq" json:"asynq" toml:"asynq"`
	LogInstance     string      `yaml:"log_instance" json:"log_instance" toml:"log_instance" default:"default"`
}

Conf http configure nolint: revive // struct field annotation issue

type Embed

type Embed struct {
}

type Errcode

type Errcode int

func (Errcode) Error

func (e Errcode) Error() (r string)

func (Errcode) String

func (e Errcode) String() (r string)

String Here, i18n cannot be used for localization, because in Localize, since the code is of string type, the process of doing toString will lead to stack overflow.

type IRouter

type IRouter interface {
	Use(middlewares ...gin.HandlerFunc) IRouter

	Handle(uri string, fn routerHandler, opts ...utils.OptionExtender) IRouter
	Any(uri string, fn routerHandler, opts ...utils.OptionExtender) IRouter
	GET(uri string, fn routerHandler, opts ...utils.OptionExtender) IRouter
	POST(uri string, fn routerHandler, opts ...utils.OptionExtender) IRouter
	DELETE(uri string, fn routerHandler, opts ...utils.OptionExtender) IRouter
	PATCH(uri string, fn routerHandler, opts ...utils.OptionExtender) IRouter
	PUT(uri string, fn routerHandler, opts ...utils.OptionExtender) IRouter
	OPTIONS(uri string, fn routerHandler, opts ...utils.OptionExtender) IRouter
	HEAD(uri string, fn routerHandler, opts ...utils.OptionExtender) IRouter
	Group(relativePath string, handlers ...gin.HandlerFunc) IRouter

	StaticFile(string, string) IRouter
	StaticFileFS(string, string, http.FileSystem) IRouter
	Static(string, string) IRouter
	StaticFS(string, http.FileSystem) IRouter

	ServeHTTP(http.ResponseWriter, *http.Request)
	Config() OutputConf
	ListenAndServe() error
	Start()
}
var (
	Router IRouter
)

func Use

func Use(opts ...utils.OptionExtender) IRouter

type OutputConf

type OutputConf struct {
	Port         int
	TLS          bool
	Cert         string
	Key          string
	NextProtos   []string
	SuccessCode  int
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	AsynqConf    []asynqConf
}

type Response

type Response struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`

	// pagination
	Page  *int `json:"page,omitempty"`
	Count *int `json:"count,omitempty"`

	// Trace
	TraceID string `json:"traceid"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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