2017-08-18 11:30:29 +00:00
|
|
|
package overflow_gateway_websocket
|
|
|
|
|
2017-08-21 10:23:45 +00:00
|
|
|
import (
|
|
|
|
"git.loafle.net/overflow/overflow_gateway_websocket/backend"
|
|
|
|
"git.loafle.net/overflow/overflow_gateway_websocket/pubsub"
|
|
|
|
"git.loafle.net/overflow/overflow_gateway_websocket/pubsub/redis"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2017-08-18 11:30:29 +00:00
|
|
|
type (
|
|
|
|
// OnPreRequestFunc is callback function
|
|
|
|
OnPreRequestFunc func()
|
|
|
|
OnPostRequestFunc func()
|
|
|
|
OnPreNotifyFunc func()
|
|
|
|
OnPrePushFunc func()
|
|
|
|
)
|
|
|
|
|
|
|
|
type Server interface {
|
|
|
|
OnPreRequest(cb OnPreRequestFunc)
|
|
|
|
OnPostRequest(cb OnPostRequestFunc)
|
|
|
|
OnPreNotify(cb OnPreNotifyFunc)
|
|
|
|
OnPrePush(cb OnPrePushFunc)
|
|
|
|
ListenAndServe()
|
|
|
|
}
|
|
|
|
|
|
|
|
type server struct {
|
|
|
|
onPreRequestListeners []OnPreRequestFunc
|
|
|
|
onPostRequestListeners []OnPostRequestFunc
|
|
|
|
onPreNotifyListeners []OnPreNotifyFunc
|
|
|
|
onPrePushListeners []OnPrePushFunc
|
2017-08-21 10:23:45 +00:00
|
|
|
|
|
|
|
backendPool backend.Pool
|
|
|
|
pubSub pubsub.PubSub
|
2017-08-18 11:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServer() Server {
|
|
|
|
s := &server{
|
|
|
|
onPreRequestListeners: make([]OnPreRequestFunc, 0),
|
|
|
|
onPostRequestListeners: make([]OnPostRequestFunc, 0),
|
|
|
|
onPreNotifyListeners: make([]OnPreNotifyFunc, 0),
|
|
|
|
onPrePushListeners: make([]OnPrePushFunc, 0),
|
|
|
|
}
|
2017-08-21 10:23:45 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
s.backendPool, err = backend.NewPool(backend.Options{
|
|
|
|
Dial: func() (*grpc.ClientConn, error) {
|
|
|
|
return nil, nil
|
|
|
|
},
|
|
|
|
NewClient: func(*grpc.ClientConn) (backend.BackendClient, error) {
|
|
|
|
return nil, nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if nil != err {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s.pubSub, err = redis.New("")
|
|
|
|
if nil != err {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-18 11:30:29 +00:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *server) OnPreRequest(cb OnPreRequestFunc) {
|
|
|
|
s.onPreRequestListeners = append(s.onPreRequestListeners, cb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *server) OnPostRequest(cb OnPostRequestFunc) {
|
|
|
|
s.onPostRequestListeners = append(s.onPostRequestListeners, cb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *server) OnPreNotify(cb OnPreNotifyFunc) {
|
|
|
|
s.onPreNotifyListeners = append(s.onPreNotifyListeners, cb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *server) OnPrePush(cb OnPrePushFunc) {
|
|
|
|
s.onPrePushListeners = append(s.onPrePushListeners, cb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *server) ListenAndServe() {
|
|
|
|
|
|
|
|
}
|