server

package
v0.0.0-...-d07672d Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DetermineRequestContentTypeError = errors.New("failed to determine the request content type. set http header with Content-Type")
View Source
var RouteNoRegisteredError = errors.New("router group not registered")

Functions

func GenerateRequestBody

func GenerateRequestBody(c *gin.Context) string

GenerateRequestBody 从Gin的上下文中读取HTTP请求的Body,并将其存储到一个Buffer Pool对象中。

func GenerateRequestPath

func GenerateRequestPath(c *gin.Context) string

func GenerateResponseBody

func GenerateResponseBody(c *gin.Context) string

func ParseRequestBody

func ParseRequestBody(c *gin.Context, value interface{}, emptyRequestBodyContent bool) error

ParseRequestBody 将 request body 解析为指定类型 value 的变量,emptyRequestBodyContent 表示是否允许为空。

Types

type Engine

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

func NewEngine

func NewEngine(httpConf *HttpServerConf, featureOpts *FeatureOpts, middlewares *[]gin.HandlerFunc) *Engine

func (*Engine) GetHttpRegisteredGroup

func (e *Engine) GetHttpRegisteredGroup(path string) (*gin.RouterGroup, error)

GetHttpRegisteredGroup 获得已经注册的路由组

func (*Engine) HttpRouteGroupRegistry

func (e *Engine) HttpRouteGroupRegistry(path string, baseRouteGroup *gin.RouterGroup)

HttpRouteGroupRegistry 注册一个路由组

func (*Engine) HttpServiceRegistry

func (e *Engine) HttpServiceRegistry(services ...httpServiceInterface)

HttpServiceRegistry 注册服务到 Engine

func (*Engine) Start

func (e *Engine) Start()

func (*Engine) Stop

func (e *Engine) Stop()

type FeatureOpts

type FeatureOpts struct {
	EnableGinRedirectTrailingSlash bool `json:"enableGinRedirectTrailingSlash,omitempty" yaml:"enableGinRedirectTrailingSlash,omitempty"` // 内部 301 路径跳转,如果当前路径的处理函数不存在,但是路径+'/'的处理函数存在,则允许进行重定向
	EnableGinRedirectFixedPath     bool `json:"enableGinRedirectFixedPath,omitempty" yaml:"enableGinRedirectFixedPath,omitempty"`         // 允许修复当前请求路径,如/FOO和/..//Foo会被修复为/foo,并进行重定向,默认为 false。
	EnableGinForwardedByClientIP   bool `json:"enableGinForwardedByClientIP,omitempty" yaml:"enableGinForwardedByClientIP,omitempty"`     // 如果应用程序不在代理之后,“ForwardedByClientIP”应设置为 false,因此“X-Forwarded-For”将被忽略。 如果在代理后面将其设置为true。
	EnableRecordContextBody        bool `json:"EnableRecordContextBody,omitempty" yaml:"EnableRecordContextBody,omitempty"`               // 记录会话 body 内容
	EnableHttpHealthCheck          bool `json:"enableHttpHealthCheck,omitempty" yaml:"enableHttpHealthCheck,omitempty"`                   // 健康检查
	EnableMetrics                  bool `json:"enableMetrics,omitempty" yaml:"enableMetrics,omitempty"`                                   // 记录 Prometheus 数据
	EnableSwagger                  bool `json:"enableSwagger,omitempty" yaml:"enableSwagger,omitempty"`                                   // Swagger
	EnableHttpPProf                bool `json:"enableHttpPProf,omitempty" yaml:"enableHttpPProf,omitempty"`                               // running time debug
}

func NewDefaultFeatureOpts

func NewDefaultFeatureOpts() *FeatureOpts

type HttpServerConf

type HttpServerConf struct {
	Address               string             `json:"address" yaml:"address"`
	Port                  uint16             `json:"port" yaml:"port"`
	HttpReadTimeout       uint32             `json:"httpReadTimeout,omitempty" yaml:"httpReadTimeout,omitempty"`
	HttpWriteTimeout      uint32             `json:"httpWriteTimeout,omitempty" yaml:"httpWriteTimeout,omitempty"`
	HttpReadHeaderTimeout uint32             `json:"httpReadHeaderTimeout,omitempty" yaml:"httpReadHeaderTimeout,omitempty"`
	Logger                *zap.SugaredLogger `json:"-" yaml:"-"`
}

func NewDefaultHttpServerConfig

func NewDefaultHttpServerConfig() *HttpServerConf

type HttpService

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

func NewHttpService

func NewHttpService(f func(*gin.RouterGroup)) *HttpService

func (*HttpService) RoutesRegistry

func (s *HttpService) RoutesRegistry(e *Engine)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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