httpServer

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpServer

type HttpServer struct {
	// 配置属性
	ListenAddr    string          `ini:"listen_addr" json:"listen_addr" yaml:"listen_addr"`
	ServerName    []string        `ini:"server_name,omitempty" json:"server_name" yaml:"server_name"` // 绑定域名
	Ssl           bool            `ini:"ssl" json:"ssl" yaml:"ssl"`
	Ca            string          `ini:"ca" json:"ca" yaml:"ca"`
	Crt           string          `ini:"crt" json:"crt" yaml:"crt"`
	Key           string          `ini:"key" json:"key" yaml:"key"`
	SocketTimeout time.Duration   `ini:"socket_timeout" json:"socket_timeout" yaml:"socket_timeout"` // socket 心跳超时时间
	Hotupdate     bool            `ini:"hotupdate" json:"hotupdate" yaml:"hotupdate"`                // 是否启动热加载
	EnableGzip    bool            `ini:"enable_gzip" json:"enable_gzip" yaml:"enable_gzip"`          // 是否开启gzip
	Security      SecurityConfig  `ini:"security" json:"security" yaml:"security"`                   // 安全配置
	Logger        zaploger.Config `json:"logger" yaml:"logger" ini:"logger" gorm:"comment:日志配置"`
	Allowip       []string        `ini:"allowip,omitempty" json:"allowip" yaml:"allowip"` // Deprecated: 请使用 addRoute
	Denyip        []string        `ini:"denyip,omitempty" json:"denyip" yaml:"denyip"`    // Deprecated: 请使用 addRoute

	Route          map[string]http.HandlerFunc                       `yaml:"-" json:"-"` // Deprecated: 请使用 addRoute
	RouteHandle    map[string]http.Handler                           `yaml:"-" json:"-"` // Deprecated: 请使用 addRoute
	RouteSocket    map[string]func(ws *websocket.Conn)               `yaml:"-" json:"-"` // Deprecated: 请使用 addRoute
	CommonCallback func(w http.ResponseWriter, r *http.Request) bool `yaml:"-" json:"-"` // Deprecated: 请使用 addRoute
	// contains filtered or unexported fields
}

func (*HttpServer) Group

func (h *HttpServer) Group(g string) *RouterGroup

func (*HttpServer) HttpServerStart

func (h *HttpServer) HttpServerStart(ctx context.Context)

HttpServerStart 公功 http server 启动函数

type IPAccessConfig

type IPAccessConfig struct {
	Enable bool            `ini:"enable" json:"enable" yaml:"enable"`
	Allow  *ipmatch.Config `ini:"allow" json:"allow" yaml:"allow"` // 允许的IP
	Deny   *ipmatch.Config `ini:"deny" json:"deny" yaml:"deny"`    // 屏蔽的IP
	Debug  *ipmatch.Config `ini:"debug" json:"debug" yaml:"debug"` // 调试允许的IP
}

type MiddlewareFunc

type MiddlewareFunc func(next http.Handler) http.Handler

MiddlewareFunc 修改为支持 http.Handler

func Chain

func Chain(middlewares ...MiddlewareFunc) MiddlewareFunc

Chain 中间件链(兼容 http.Handler)

type RouteType

type RouteType int
const (
	RouteTypeHTTP RouteType = iota
	RouteTypeWebSocket
)

type RouterGroup

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

func (*RouterGroup) Any

func (g *RouterGroup) Any(p string, handler http.HandlerFunc)

func (*RouterGroup) AnyHandler

func (g *RouterGroup) AnyHandler(p string, handler http.Handler)

func (*RouterGroup) Connect

func (g *RouterGroup) Connect(p string, handler http.HandlerFunc)

func (*RouterGroup) ConnectHandler

func (g *RouterGroup) ConnectHandler(p string, handler http.Handler)

func (*RouterGroup) Delete

func (g *RouterGroup) Delete(p string, handler http.HandlerFunc)

func (*RouterGroup) DeleteHandler

func (g *RouterGroup) DeleteHandler(p string, handler http.Handler)

func (*RouterGroup) Get

func (g *RouterGroup) Get(p string, handler http.HandlerFunc)

func (*RouterGroup) GetHandler

func (g *RouterGroup) GetHandler(p string, handler http.Handler)

func (*RouterGroup) Group

func (g *RouterGroup) Group(prefix string) *RouterGroup

Group 创建新分组

func (*RouterGroup) Head

func (g *RouterGroup) Head(p string, handler http.HandlerFunc)

func (*RouterGroup) HeadHandler

func (g *RouterGroup) HeadHandler(p string, handler http.Handler)

func (*RouterGroup) Options

func (g *RouterGroup) Options(p string, handler http.HandlerFunc)

func (*RouterGroup) OptionsHandler

func (g *RouterGroup) OptionsHandler(p string, handler http.Handler)

func (*RouterGroup) Patch

func (g *RouterGroup) Patch(p string, handler http.HandlerFunc)

func (*RouterGroup) PatchHandler

func (g *RouterGroup) PatchHandler(p string, handler http.Handler)

func (*RouterGroup) Post

func (g *RouterGroup) Post(p string, handler http.HandlerFunc)

func (*RouterGroup) PostHandler

func (g *RouterGroup) PostHandler(p string, handler http.Handler)

func (*RouterGroup) Put

func (g *RouterGroup) Put(p string, handler http.HandlerFunc)

func (*RouterGroup) PutHandler

func (g *RouterGroup) PutHandler(p string, handler http.Handler)

func (*RouterGroup) Trace

func (g *RouterGroup) Trace(p string, handler http.HandlerFunc)

func (*RouterGroup) TraceHandler

func (g *RouterGroup) TraceHandler(p string, handler http.Handler)

func (*RouterGroup) Use

func (g *RouterGroup) Use(middleware ...MiddlewareFunc) *RouterGroup

Use 支持链式调用

func (*RouterGroup) Ws

func (g *RouterGroup) Ws(p string, handler func(ws *websocket.Conn))

Ws 添加 WebSocket 支持

type SecurityConfig

type SecurityConfig struct {
	DefaultValidLast bool           `ini:"default_valid_last" json:"default_valid_last" yaml:"default_valid_last"` // 默认验证器是否放最后
	CORS             *cors.Config   `ini:"cors" json:"cors" yaml:"cors"`                                           // 跨域配置
	IPAccess         IPAccessConfig `ini:"ip_access" json:"ip_access" yaml:"ip_access"`                            // IP访问控制
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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