Documentation
¶
Index ¶
- type Account
- type Context
- func (c *Context) Abort()
- func (c *Context) Account() *Account
- func (c *Context) Bind(obj any) error
- func (c *Context) BindHeader(header any) error
- func (c *Context) BindUri(uri any) error
- func (c *Context) ContentType() string
- func (c *Context) Fail(code int)
- func (c *Context) Header() http.Header
- func (c *Context) IP() string
- func (c *Context) Next()
- func (c *Context) OK(data any)
- func (c *Context) Path() string
- func (c *Context) Response(code int, data any)
- func (c *Context) SetAccount(account *Account)
- type ContextHandler
- type GrpcServer
- type HttpServer
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
func (*Context) ContentType ¶
ContentType 返回 Content-Type header
type ContextHandler ¶
type ContextHandler func(ctx *Context)
type GrpcServer ¶ added in v0.0.24
type GrpcServer struct {
// contains filtered or unexported fields
}
GrpcServer 封装一个可控生命周期的 gRPC 服务
func NewGrpc ¶ added in v0.0.24
func NewGrpc(opts Options) (*GrpcServer, error)
NewGrpc 创建 gRPC GrpcServer(不启动监听)
func (*GrpcServer) GracefulStop ¶ added in v0.0.24
func (s *GrpcServer) GracefulStop(timeout time.Duration)
GracefulStop 在给定超时时间内优雅退出,否则强制 Stop。
func (*GrpcServer) Start ¶ added in v0.0.24
func (s *GrpcServer) Start(ctx context.Context) error
Start 监听并启动服务;阻塞直到 ctx 取消或监听出错。 一般由外部用 goroutine 并发启动多个服务(HTTP/GRPC),统一等 ctx.Done().
func (*GrpcServer) Stop ¶ added in v0.0.24
func (s *GrpcServer) Stop()
Stop 立即关闭(不优雅)。一般只在优雅退出超时兜底时调用。
type HttpServer ¶ added in v0.0.24
func (*HttpServer) GET ¶ added in v0.0.24
func (s *HttpServer) GET(path string, handles ...ContextHandler)
GET 注册GET请求处理函数
func (*HttpServer) POST ¶ added in v0.0.24
func (s *HttpServer) POST(path string, handles ...ContextHandler)
POST 注册POST请求处理函数
func (*HttpServer) Use ¶ added in v0.0.24
func (s *HttpServer) Use(handles ...ContextHandler)
Use 注册中间件处理函数
type Options ¶ added in v0.0.24
type Options struct {
Addr string
TLSCertFile string // 可选:服务端证书
TLSKeyFile string // 可选:服务端私钥
TLSClientCAFile string // 可选:开启双向 TLS 时的 Client CA
EnableReflection bool
GracefulTimeout time.Duration
UnaryInts []grpc.UnaryServerInterceptor
StreamInts []grpc.StreamServerInterceptor
// Register 用于注册你的具体 gRPC 服务(pb.RegisterXxxServer)
Register func(s *grpc.Server) error
}
Options 服务配置
Click to show internal directories.
Click to hide internal directories.