This commit is contained in:
2025-06-24 22:09:05 +08:00
parent 32a7a512a2
commit fdac99f11c
38 changed files with 42980 additions and 180 deletions

View File

@@ -18,6 +18,7 @@ type Server struct {
workerPool *goroutine.Pool
codec codec.SocketCodec
handler handler.Handler
discorse bool
}
type Option func(*Server)
@@ -31,6 +32,7 @@ func NewServer(options ...Option) *Server {
workerPool: goroutine.Default(),
bufferSize: 4096, //默认缓冲区大小
multicore: true,
discorse: true,
}
for _, option := range options {
option(server)
@@ -43,7 +45,11 @@ func WithSocketCodec(codec codec.SocketCodec) Option {
u.codec = codec
}
}
func WithCORS() Option {
return func(u *Server) {
u.discorse = false
}
}
func WithSocketHandler(handler handler.Handler) Option {
return func(u *Server) {
u.handler = handler