webserver

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Server)

func WithIdleTimeout

func WithIdleTimeout(d time.Duration) Option

func WithMetadata

func WithMetadata(md map[string]string) Option

func WithMiddleware

func WithMiddleware(middlewares ...func(http.Handler) http.Handler) Option

WithMiddleware 添加 HTTP 中间件

func WithReadTimeout

func WithReadTimeout(d time.Duration) Option

func WithRegionInfo added in v0.8.0

func WithRegionInfo(region, zone, campus string) Option

WithRegionInfo 设置地域信息(region/zone/campus),与 grpcserver.WithRegionInfo 对齐。 用于 LocalityRouter 地域亲和路由和 LabelFilter 标签过滤。

func WithServiceName

func WithServiceName(name string) Option

func WithShutdownTimeout

func WithShutdownTimeout(d time.Duration) Option

WithShutdownTimeout 设置 HTTP 服务优雅关闭的最长等待时间,默认 30s。

func WithTLS

func WithTLS(certFile, keyFile string) Option

WithTLS 通过证书文件启用 HTTPS。certFile 和 keyFile 为 PEM 格式文件路径。

func WithTLSConfig

func WithTLSConfig(cfg *tls.Config) Option

WithTLSConfig 通过自定义 tls.Config 启用 HTTPS,适合 mTLS 或自定义 CA 场景。

func WithVersion

func WithVersion(version string) Option

WithVersion 将服务版本写入 metadata,注册到注册中心后可见,灰度发布时可用于流量路由。

func WithWriteTimeout

func WithWriteTimeout(d time.Duration) Option

type Server

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

func New

func New(addr string, mux http.Handler, opts ...Option) *Server

func (*Server) Addr

func (s *Server) Addr() string

func (*Server) ID

func (s *Server) ID() string

func (*Server) Kind

func (s *Server) Kind() string

func (*Server) Metadata

func (s *Server) Metadata() map[string]string

func (*Server) Name

func (s *Server) Name() string

func (*Server) Ready

func (s *Server) Ready() <-chan struct{}

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

func (*Server) String

func (s *Server) String() string

Jump to

Keyboard shortcuts

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