YHEchoPackage/ws/engine.go

47 lines
980 B
Go
Raw Permalink Normal View History

2023-02-09 13:35:14 +08:00
/*
* (c) 2022.
* .
*
* :mic
* Email:funui@outlook.com
*/
package wsgnet
import (
"fmt"
2023-02-09 16:39:45 +08:00
"git.yhrjkj.com/YuanHong/YHEchoPackage/ws/internal"
2023-02-09 13:35:14 +08:00
goPool "github.com/panjf2000/gnet/v2/pkg/pool/goroutine"
"github.com/zeromicro/go-zero/core/logx"
)
type engine struct {
conf EchoConf
routes featuredRoutes
}
func newEngine(c EchoConf) *engine {
svr := &engine{
conf: c,
}
return svr
}
func (ng *engine) addRoutes(r featuredRoutes) {
ng.routes = r
}
func (ng *engine) start() error {
ss := &GnetServer{
workerPool: goPool.Default(),
network: ng.conf.Network,
addr: fmt.Sprintf("%s:%d", ng.conf.Host, ng.conf.Port),
}
ss.addRoutes(ng.routes)
return internal.StartEcho(ss, ng.conf.Network, ng.conf.Host, ng.conf.Port)
}
func (ng *engine) stop() error {
internal.StopEcho(ng.conf.Network, ng.conf.Host, ng.conf.Port)
return logx.Close()
}