member_gateway_rest/server/server-handler.go

59 lines
1.2 KiB
Go
Raw Normal View History

2018-04-06 10:08:38 +00:00
package server
import (
2018-04-11 14:23:47 +00:00
ccf "git.loafle.net/commons/cors-go/fasthttp"
2018-04-10 06:58:38 +00:00
cs "git.loafle.net/commons/server-go"
2018-05-11 08:00:33 +00:00
oe "git.loafle.net/overflow/external-go"
2018-04-10 06:58:38 +00:00
ogrs "git.loafle.net/overflow/gateway_rest/server"
"git.loafle.net/overflow/member_gateway_rest/config"
2018-04-11 13:08:41 +00:00
"github.com/valyala/fasthttp"
2018-04-06 10:08:38 +00:00
)
2018-04-06 12:17:07 +00:00
type ServerHandler interface {
2018-04-10 06:58:38 +00:00
ogrs.ServerHandler
2018-04-06 10:08:38 +00:00
}
2018-04-06 12:17:07 +00:00
type ServerHandlers struct {
2018-04-10 06:58:38 +00:00
ogrs.ServerHandlers
2018-04-11 14:23:47 +00:00
Config *config.Config
2018-04-11 13:08:41 +00:00
corsHandler ccf.Cors
2018-04-10 06:58:38 +00:00
}
func (sh *ServerHandlers) Init(serverCtx cs.ServerCtx) error {
if err := sh.ServerHandlers.Init(serverCtx); nil != err {
return err
}
2018-05-11 08:00:33 +00:00
oe.InitPackage(sh.Config.External)
2018-04-10 06:58:38 +00:00
2018-04-11 13:08:41 +00:00
sh.corsHandler = ccf.AllowAll()
2018-04-10 06:58:38 +00:00
return nil
}
func (sh *ServerHandlers) OnStart(serverCtx cs.ServerCtx) error {
if err := sh.ServerHandlers.OnStart(serverCtx); nil != err {
return err
}
2018-05-11 08:00:33 +00:00
oe.StartPackage(sh.Config.External)
2018-04-10 06:58:38 +00:00
return nil
}
func (sh *ServerHandlers) OnStop(serverCtx cs.ServerCtx) {
2018-05-11 08:00:33 +00:00
oe.StopPackage(sh.Config.External)
2018-04-10 06:58:38 +00:00
sh.ServerHandlers.OnStop(serverCtx)
}
func (sh *ServerHandlers) Destroy(serverCtx cs.ServerCtx) {
2018-05-11 08:00:33 +00:00
oe.DestroyPackage(sh.Config.External)
2018-04-10 06:58:38 +00:00
sh.ServerHandlers.Destroy(serverCtx)
2018-04-06 10:08:38 +00:00
}
2018-04-11 13:08:41 +00:00
func (sh *ServerHandlers) CheckOrigin(ctx *fasthttp.RequestCtx) bool {
return sh.corsHandler.Handle(ctx)
}