server

package
v0.0.0-...-80248e1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const ReportIntervalSecondDefault int64 = 30 // etcd-上报时间间隔 秒

Variables

View Source
var GServerStatus uint32

Functions

func IsServerStopping

func IsServerStopping() bool

IsServerStopping 服务是否关闭中

func SetServerStopping

func SetServerStopping()

SetServerStopping 设置为关闭中

Types

type Actor

type Actor struct {
	*xactor.Actor[uint64] // actor, 该 id 为 server id
}

func NewActor

func NewActor(id uint64, behavior xactor.Behavior) *Actor

NewActor creates a new Actor with the given id and behavior.

id: server id.

type IServer

type IServer interface {
	PreStart(ctx context.Context, opts ...*Options) (err error) // 服务启动前的处理 - 资源准备
	Start(ctx context.Context) (err error)                      // 启动服务
	PostStart() (err error)                                     // 服务启动后的处理 - 资源准备完成
	PreStop() (err error)                                       // 服务关闭前的处理 - 关闭资源前
	Stop() (err error)                                          // 停止服务 - 关闭 bus 之后

	GetOptions() (opt *Options)
}

type Options

type Options struct {
	TCPHandler       xnetcommon.IHandler
	KCPHandler       xnetcommon.IHandler
	WebsocketHandler xnetcommon.IHandler
	LogCallback      xcontrol.ICallBack
	HeaderStrategy   xpacket.IHeaderStrategy
	Etcd             *xetcd.Options
}

func NewServerOptions

func NewServerOptions() *Options

NewServerOptions 新的ServerOptions

func (*Options) WithEtcd

func (p *Options) WithEtcd(etcd *xetcd.Options) *Options

func (*Options) WithHeaderStrategy

func (p *Options) WithHeaderStrategy(strategy xpacket.IHeaderStrategy) *Options

func (*Options) WithKCPHandler

func (p *Options) WithKCPHandler(handler xnetcommon.IHandler) *Options

func (*Options) WithLogCallbackFunc

func (p *Options) WithLogCallbackFunc(callback xcontrol.ICallBack) *Options

func (*Options) WithTCPHandler

func (p *Options) WithTCPHandler(handler xnetcommon.IHandler) *Options

func (*Options) WithWebsocketHandler

func (p *Options) WithWebsocketHandler(handler xnetcommon.IHandler) *Options

type Server

type Server struct {
	QuitChan chan struct{} // 退出信号, 用于关闭服务

	TCPServer  *xnettcp.Server
	KCPServer  *xnetkcp.Server
	GRPCServer *xgrpc.Server
	WebSocket  *xnetwebsocket.Server

	Options *Options
	Derived IServer // 服务实例
	// contains filtered or unexported fields
}

func NewServer

func NewServer(args []string) *Server

NewServer 创建服务 args: [0:程序名称] [1:配置文件绝对路径]

func (*Server) GetActor

func (p *Server) GetActor() *Actor

func (*Server) GetOptions

func (p *Server) GetOptions() (opt *Options)

func (*Server) PostStart

func (p *Server) PostStart() error

func (*Server) PreStart

func (p *Server) PreStart(ctx context.Context, opts ...*Options) error

func (*Server) PreStop

func (p *Server) PreStop() error

func (*Server) Start

func (p *Server) Start(ctx context.Context) (err error)

func (*Server) Stop

func (p *Server) Stop() (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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