Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// 监听地址
	Addr string `yaml:"addr" json:"addr"`

	// 读取超时
	ReadTimeout time.Duration `yaml:"read_timeout" json:"read_timeout"`

	// 写入超时
	WriteTimeout time.Duration `yaml:"write_timeout" json:"write_timeout"`

	// 空闲超时
	IdleTimeout time.Duration `yaml:"idle_timeout" json:"idle_timeout"`

	// 最大请求头大小
	MaxHeaderBytes int `yaml:"max_header_bytes" json:"max_header_bytes"`

	// 优雅关闭超时
	ShutdownTimeout time.Duration `yaml:"shutdown_timeout" json:"shutdown_timeout"`
}

Config 服务器配置

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 返回默认服务器配置

type Manager

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

Manager HTTP 服务器管理器

func NewManager

func NewManager(handler http.Handler, config Config, logger *zap.Logger) *Manager

NewManager 创建服务器管理器

func (*Manager) Addr

func (m *Manager) Addr() string

Addr 返回服务器监听地址

func (*Manager) Errors

func (m *Manager) Errors() <-chan error

Errors returns asynchronous server errors.

func (*Manager) IsRunning

func (m *Manager) IsRunning() bool

IsRunning 检查服务器是否运行中

func (*Manager) Shutdown

func (m *Manager) Shutdown(ctx context.Context) error

Shutdown 优雅关闭服务器

func (*Manager) Start

func (m *Manager) Start() error

Start 启动服务器(非阻塞)

func (*Manager) StartTLS

func (m *Manager) StartTLS(certFile, keyFile string) error

StartTLS 启动 HTTPS 服务器(非阻塞)

func (*Manager) WaitForShutdown

func (m *Manager) WaitForShutdown()

WaitForShutdown 等待关闭信号

Jump to

Keyboard shortcuts

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