http

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Client *resty.Client
)

Functions

func AppName

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

func CName

func CName(name string) utils.OptionFunc[clientOption]

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 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 New

func New(opts ...utils.OptionExtender) *resty.Client

func NewRequest

func NewRequest(ctx context.Context, opts ...utils.OptionExtender) *resty.Request

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 RetryCondition

func RetryCondition(fn resty.RetryConditionFunc) utils.OptionFunc[clientOption]

func RetryHook

func RetryHook(fn resty.OnRetryFunc) utils.OptionFunc[clientOption]

func StaticFileZeroCopy

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

StaticFileZeroCopy zero copy gin handler wrapper for static file

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"`
	ErrorCode       int                    `yaml:"error_code" json:"error_code" toml:"error_code" default:"-1"`
	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"`
	EnableLogger    bool                   `yaml:"enable_logger" json:"enable_logger" toml:"enable_logger"`
	LogInstance     string                 `yaml:"log_instance" json:"log_instance" toml:"log_instance" default:"default"`
	Logger          string                 `yaml:"logger" json:"logger" toml:"logger" default:"github.com/wfusion/gofusion/log/customlogger.httpLogger"`
	Asynq           []asynqConf            `yaml:"asynq" json:"asynq" toml:"asynq"`
	Clients         map[string]*clientConf `yaml:"clients" json:"clients" toml:"clients"`
}

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()

	Running() <-chan struct{}
	Closing() <-chan struct{}
	// contains filtered or unexported methods
}
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