You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB
Go

package nnet
import (
lifecyclepkg "github.com/noahlann/nnet/pkg/lifecycle"
)
// ServerLifecycleHook 服务器生命周期钩子类型别名
type ServerLifecycleHook = lifecyclepkg.ServerLifecycleHook
// ConnectionLifecycleHook 连接生命周期钩子类型别名
type ConnectionLifecycleHook = lifecyclepkg.ConnectionLifecycleHook
// ServerHookFunc 服务器钩子函数类型别名
type ServerHookFunc = lifecyclepkg.ServerHookFunc
// ConnectionHookFunc 连接钩子函数类型别名
type ConnectionHookFunc = lifecyclepkg.ConnectionHookFunc
// HookFunc 钩子函数类型别名
type HookFunc = lifecyclepkg.HookFunc
// NewServerHookFunc 创建服务器钩子函数
func NewServerHookFunc(onInit, onStart, onStop HookFunc) *ServerHookFunc {
return &ServerHookFunc{
OnInitFunc: onInit,
OnStartFunc: onStart,
OnStopFunc: onStop,
}
}
// NewConnectionHookFunc 创建连接钩子函数
func NewConnectionHookFunc(
onOpen func(connID string, remoteAddr string) error,
onTraffic func(connID string, data []byte) error,
onClose func(connID string, err error) error,
onError func(connID string, err error) error,
) *ConnectionHookFunc {
return &ConnectionHookFunc{
OnOpenFunc: onOpen,
OnTrafficFunc: onTraffic,
OnCloseFunc: onClose,
OnErrorFunc: onError,
}
}