member_gateway_rest/server/server-handler.go
crusader e851c9f3bb ing
2018-05-11 17:00:33 +09:00

59 lines
1.2 KiB
Go

package server
import (
ccf "git.loafle.net/commons/cors-go/fasthttp"
cs "git.loafle.net/commons/server-go"
oe "git.loafle.net/overflow/external-go"
ogrs "git.loafle.net/overflow/gateway_rest/server"
"git.loafle.net/overflow/member_gateway_rest/config"
"github.com/valyala/fasthttp"
)
type ServerHandler interface {
ogrs.ServerHandler
}
type ServerHandlers struct {
ogrs.ServerHandlers
Config *config.Config
corsHandler ccf.Cors
}
func (sh *ServerHandlers) Init(serverCtx cs.ServerCtx) error {
if err := sh.ServerHandlers.Init(serverCtx); nil != err {
return err
}
oe.InitPackage(sh.Config.External)
sh.corsHandler = ccf.AllowAll()
return nil
}
func (sh *ServerHandlers) OnStart(serverCtx cs.ServerCtx) error {
if err := sh.ServerHandlers.OnStart(serverCtx); nil != err {
return err
}
oe.StartPackage(sh.Config.External)
return nil
}
func (sh *ServerHandlers) OnStop(serverCtx cs.ServerCtx) {
oe.StopPackage(sh.Config.External)
sh.ServerHandlers.OnStop(serverCtx)
}
func (sh *ServerHandlers) Destroy(serverCtx cs.ServerCtx) {
oe.DestroyPackage(sh.Config.External)
sh.ServerHandlers.Destroy(serverCtx)
}
func (sh *ServerHandlers) CheckOrigin(ctx *fasthttp.RequestCtx) bool {
return sh.corsHandler.Handle(ctx)
}