server

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Uid     int64
	AppId   int64
	Lang    string
	Version string
	Os      int
	Ltm     int64
}

type Context

type Context struct {
	GinCtx *gin.Context
}

func (*Context) Abort

func (c *Context) Abort()

Abort 终端执行

func (*Context) Account

func (c *Context) Account() *Account

Account 返回用户账号相关信息

func (*Context) Bind

func (c *Context) Bind(obj any) error

Bind 绑定请求体到obj

func (*Context) BindHeader

func (c *Context) BindHeader(header any) error

BindHeader 绑定header

func (*Context) BindUri

func (c *Context) BindUri(uri any) error

BindUri 绑定uri

func (*Context) ContentType

func (c *Context) ContentType() string

ContentType 返回 Content-Type header

func (*Context) Fail

func (c *Context) Fail(code int)

Fail 响应失败,data为响应的数据

func (*Context) Header

func (c *Context) Header() http.Header

Header 返回http请求头

func (*Context) IP

func (c *Context) IP() string

IP 返回客户端真实IP

func (*Context) Next

func (c *Context) Next()

Next 执行下一个handler

func (*Context) OK

func (c *Context) OK(data any)

OK 响应成功,data为响应的数据

func (*Context) Path

func (c *Context) Path() string

Path 返回客户端完整地址

func (*Context) Response

func (c *Context) Response(code int, data any)

Response 响应请求,code为状态码,data 响应的数据

func (*Context) SetAccount

func (c *Context) SetAccount(account *Account)

SetAccount 设置用户账号相关信息

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

type HttpServer struct {
	*gin.Engine
}

func NewHTTP added in v0.0.24

func NewHTTP(isDebug bool) *HttpServer

NewHTTP 初始化HTTP服务器引擎

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) Run added in v0.0.24

func (s *HttpServer) Run(addr ...string)

Run 启动HTTP服务器

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 服务配置

Directories

Path Synopsis
test
pb

Jump to

Keyboard shortcuts

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