project shared

This commit is contained in:
geek
2017-11-23 19:33:19 +09:00
commit 181562a5c1
24 changed files with 866 additions and 0 deletions

9
server/server_handler.go Normal file
View File

@@ -0,0 +1,9 @@
package server
import (
oogws "git.loafle.net/overflow/overflow_gateway_websocket/server"
)
type ServerHandler interface {
oogws.ServerHandler
}

51
server/server_handlers.go Normal file
View File

@@ -0,0 +1,51 @@
package server
import (
oogws "git.loafle.net/overflow/overflow_gateway_websocket/server"
"github.com/valyala/fasthttp"
)
func NewServerHandler() ServerHandler {
sh := &ServerHandlers{}
sh.ServerHandler = oogws.NewServerHandler()
return sh
}
type ServerHandlers struct {
oogws.ServerHandler
}
// Init invoked before the server is started
// If you override ths method, must call
func (sh *ServerHandlers) Init() error {
if err := sh.ServerHandler.Init(); nil != err {
return err
}
return nil
}
func (sh *ServerHandlers) OnStart() {
sh.ServerHandler.OnStart()
}
func (sh *ServerHandlers) CheckOrigin(ctx *fasthttp.RequestCtx) bool {
if origin := string(ctx.Request.Header.Peek("Origin")); origin != "" {
ctx.Response.Header.Set("Access-Control-Allow-Origin", origin)
if string(ctx.Method()) == "OPTIONS" && string(ctx.Request.Header.Peek("Access-Control-Request-Method")) != "" {
ctx.Response.Header.Set("Access-Control-Allow-Headers", "Content-Type, Accept")
ctx.Response.Header.Set("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE")
}
}
return true
}
func (sh *ServerHandlers) OnStop() {
sh.ServerHandler.OnStop()
}
func (sh *ServerHandlers) Validate() {
sh.ServerHandler.Validate()
}