http

package
v0.0.0-...-213b989 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package http @file : code.go @author : china.gdxs@gmail.com @time : 2023/12/21 15:06 @Description:

Package http @file : codec.go @author : china.gdxs@gmail.com @time : 2023/11/7 17:34 @Description:

Package http @file : http.go @author : china.gdxs@gmail.com @time : 2023/11/7 17:30 @Description:

Package http @file : middleware.go @author : china.gdxs@gmail.com @time : 2023/11/7 17:35 @Description:

Package http @file : mw.logger.go @author : china.gdxs@gmail.com @time : 2023/12/20 14:48 @Description: 记录系统日志

Package http @file : mw.validate.go @author : china.gdxs@gmail.com @time : 2023/12/20 15:14 @Description:

Package http @file : options.go @author : china.gdxs@gmail.com @time : 2023/11/8 11:32 @Description:

Index

Constants

View Source
const (
	ErrValidate int = 110000
)
View Source
const OperationKey = "operation"

Variables

This section is empty.

Functions

func DefaultRequestDecoder

func DefaultRequestDecoder(c *gin.Context, v any) (err error)

DefaultRequestDecoder decodes the request body to object.

func DefaultResponseEncoder

func DefaultResponseEncoder(c *gin.Context, obj any, err error)

DefaultResponseEncoder encodes the object to the HTTP response.

Types

type DecodeRequestFunc

type DecodeRequestFunc func(*gin.Context, any) error

DecodeRequestFunc is decode request func.

type EncodeResponseFunc

type EncodeResponseFunc func(*gin.Context, any, error)

EncodeResponseFunc is encode response func.

type ErrCode

type ErrCode struct {
	// C refers to the code of the ErrCode.
	C int

	// HTTP status that should be used for the associated error code.
	HTTP int

	// External (user) facing error text.
	Ext string

	// Ref specify the reference document.
	Ref string
}

ErrCode implements `github.com/marmotedu/errors`.Coder interface.

func (ErrCode) Code

func (coder ErrCode) Code() int

Code returns the integer code of ErrCode.

func (ErrCode) HTTPStatus

func (coder ErrCode) HTTPStatus() int

HTTPStatus returns the associated HTTP status code, if any. Otherwise, returns 200.

func (ErrCode) Reference

func (coder ErrCode) Reference() string

Reference returns the reference document.

func (ErrCode) String

func (coder ErrCode) String() string

String implements stringer. String returns the external error message, if any.

type Handler

type Handler func(c *gin.Context, req any) (any, error)

Handler defines the handler invoked by Middleware.

type Middleware

type Middleware func(Handler) Handler

Middleware is HTTP/gRPC transport middleware.

func Chain

func Chain(m ...Middleware) Middleware

Chain returns a Middleware that specifies the chained handler for endpoint.

func MwLogger

func MwLogger(lg *zap.Logger) Middleware

func MwValidator

func MwValidator() Middleware

MwValidator is a validator middleware.

func MwValidator2I18n

func MwValidator2I18n(I18n *i18n.I18n, lg *zap.Logger) Middleware

MwValidator2I18n i18n 国际化 @param I18n @return middleware.Middleware

type Server

type Server struct {
	*gin.Engine
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(opts ...ServerOption) *Server

func (*Server) Bind

func (s *Server) Bind(c *gin.Context, obj any) error

Bind 请求参数绑定

func (Server) Middleware

func (this Server) Middleware(h Handler) Handler

Middleware 引用中间件

func (*Server) Result

func (s *Server) Result(c *gin.Context, obj any, err error)

Result 结果结返回

func (*Server) Start

func (this *Server) Start(ctx context.Context) (err error)

Start http server start

func (Server) Stop

func (this Server) Stop(ctx context.Context) (err error)

Stop http server stop

type ServerOption

type ServerOption func(*Server)

ServerOption is an HTTP server option.

func Address

func Address(address string) ServerOption

Address with server address.

func Filter

func Filter(filters ...gin.HandlerFunc) ServerOption

Filter with HTTP middleware option.

func IsDebug

func IsDebug() ServerOption

IsDebug open gin debug model

func Middlewares

func Middlewares(ms ...Middleware) ServerOption

Middlewares set middleware

func RequestDecoder

func RequestDecoder(dec DecodeRequestFunc) ServerOption

RequestDecoder with request decoder.

func ResponseEncoder

func ResponseEncoder(enc EncodeResponseFunc) ServerOption

ResponseEncoder with response encoder.

Jump to

Keyboard shortcuts

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