You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
483 B
33 lines
483 B
2 years ago
|
package moo
|
||
|
|
||
|
type server struct {
|
||
|
// server kind
|
||
|
Kind string
|
||
|
}
|
||
|
|
||
|
// 服务单例池
|
||
|
var serverPool = map[string]*server{}
|
||
|
|
||
|
// 单例工厂,标识于 Kind
|
||
|
func Server(kind string) *server {
|
||
|
instance, exists := serverPool[kind]
|
||
|
if !exists {
|
||
|
instance = &server{
|
||
|
Kind: kind,
|
||
|
}
|
||
|
serverPool[kind] = instance
|
||
|
}
|
||
|
return instance
|
||
|
}
|
||
|
|
||
|
func (s *server) Start() {
|
||
|
switch s.Kind {
|
||
|
case "http":
|
||
|
s.StartHttp()
|
||
|
case "websocket":
|
||
|
fallthrough
|
||
|
case "ws":
|
||
|
s.StartWebSocket()
|
||
|
}
|
||
|
}
|