Documentation
¶
Index ¶
- Variables
- func AddConnPool(userID int64, conn *connection)
- func NewConn(ctx context.Context, userID int64, server *Server, r *http.Request, ...) *connection
- func RegisterSubscribeCheck(f func(ctx context.Context, in *SubscribeInfo) error)
- func RegisterSubscribeCheck2(f func(ctx context.Context, in *SubscribeInfo) ([]map[string]any, error))
- func SendSub(ctx context.Context, body WsResp)
- func StartWsDp(s2cGzip bool, NodeID int64, event *eventBus.FastEvent, c cache.ClusterConf)
- func WithMiddleware(middleware rest.Middleware, rs ...rest.Route) []rest.Route
- func WithMiddlewares(ms []rest.Middleware, rs ...rest.Route) []rest.Route
- type Ping
- type Pong
- type RouteOption
- type RunOption
- type Server
- type SubscribeInfo
- type UserSubscribe
- type WsBody
- type WsPublish
- type WsPublishes
- type WsReq
- type WsResp
- type WsType
Constants ¶
This section is empty.
Variables ¶
var ErrSignatureConfig = errors.New("bad config for Signature")
ErrSignatureConfig is an error that indicates bad config for signature.
Functions ¶
func AddConnPool ¶
func AddConnPool(userID int64, conn *connection)
func NewConn ¶
func NewConn(ctx context.Context, userID int64, server *Server, r *http.Request, wsConn *websocket.Conn) *connection
创建ws连接
func RegisterSubscribeCheck ¶
func RegisterSubscribeCheck(f func(ctx context.Context, in *SubscribeInfo) error)
func RegisterSubscribeCheck2 ¶
func WithMiddleware ¶
WithMiddleware adds given middleware to given route.
func WithMiddlewares ¶
WithMiddlewares adds given middlewares to given routes.
Types ¶
type RouteOption ¶
type RouteOption func(r *featuredRoutes)
func WithPrefix ¶
func WithPrefix(group string) RouteOption
WithPrefix adds group as a prefix to the route paths.
type RunOption ¶
type RunOption func(*Server)
RunOption defines the method to customize a Server.
func WithNotAllowedHandler ¶
WithNotAllowedHandler returns a RunOption with not allowed handler set to given handler.
func WithNotFoundHandler ¶
WithNotFoundHandler returns a RunOption with not found handler set to given handler.
func WithRouter ¶
WithRouter returns a RunOption that make server run with given router.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
A Server is a http server.
func MustNewServer ¶
MustNewServer returns a server with given config of c and options defined in opts. Be aware that later RunOption might overwrite previous one that write the same option. The process will exit if error occurs.
func NewServer ¶
NewServer returns a server with given config of c and options defined in opts. Be aware that later RunOption might overwrite previous one that write the same option.
func (*Server) AddRoute ¶
func (s *Server) AddRoute(r rest.Route, opts ...RouteOption)
AddRoute adds given route into the Server.
func (*Server) AddRoutes ¶
func (s *Server) AddRoutes(rs []rest.Route, opts ...RouteOption)
AddRoutes add given routes into the Server.
func (*Server) PrintRoutes ¶
func (s *Server) PrintRoutes()
PrintRoutes prints the added routes to stdout.
type SubscribeInfo ¶
type UserSubscribe ¶
type UserSubscribe struct { ServerMsg *eventBus.FastEvent // contains filtered or unexported fields }
func NewUserSubscribe ¶
func NewUserSubscribe(store kv.Store, ServerMsg *eventBus.FastEvent) *UserSubscribe
type WsPublishes ¶
type WsPublishes []WsPublish
type WsReq ¶
type WsReq struct { // Method specifies the HTTP method (GET, POST, PUT, etc.). // For client requests, an empty string means GET. // // Go's HTTP client does not support sending a request with // the CONNECT method. See the documentation on Transport for // details. Method string `json:"method"` WsBody }
type WsType ¶
type WsType string
const ( Sub WsType = "up.sub" //订阅 SubRet WsType = "down.subRet" //订阅回复 Pub WsType = "down.pub" //发布 Control WsType = "up.control" //控制 ControlRet WsType = "down.controlRet" //控制回复 UnSub WsType = "up.unSub" //取消订阅 UnSubRet WsType = "down.unSubRet" //取消订阅回复 SetHandle WsType = "up.setHandle" //设置http头 UpPing WsType = "up.ping" //测试ws连接,发啥返回啥 DownPong WsType = "down.pong" //测试ws连接,发啥返回啥 )