This commit is contained in:
crusader 2017-11-28 20:08:46 +09:00
parent 5afc7459bd
commit 55f4636b8a
5 changed files with 41 additions and 27 deletions

16
main.go
View File

@ -9,14 +9,17 @@ import (
"git.loafle.net/commons_go/logging"
"git.loafle.net/overflow/overflow_gateway_webapp/server"
"git.loafle.net/overflow/overflow_gateway_webapp/servlet/web"
"git.loafle.net/overflow/overflow_gateway_webapp/servlet"
oogws "git.loafle.net/overflow/overflow_gateway_websocket/server"
)
func main() {
defer logging.Logger().Sync()
s := initializeServer()
sh := server.NewServerHandler()
servlet.ServletInit(sh)
s := oogws.New(sh)
stop := make(chan os.Signal)
signal.Notify(stop, syscall.SIGINT)
@ -36,12 +39,3 @@ func main() {
s.Stop()
}
func initializeServer() oogws.Server {
sh := server.NewServerHandler()
web.Initialize(sh)
s := oogws.New(sh)
return s
}

View File

@ -1,6 +1,7 @@
package server
import (
cwf "git.loafle.net/commons_go/websocket_fasthttp"
oogws "git.loafle.net/overflow/overflow_gateway_websocket/server"
"github.com/valyala/fasthttp"
)
@ -17,16 +18,16 @@ type ServerHandlers struct {
// 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 {
func (sh *ServerHandlers) Init(serverCTX cwf.ServerContext) error {
if err := sh.ServerHandler.Init(serverCTX); nil != err {
return err
}
return nil
}
func (sh *ServerHandlers) OnStart() {
sh.ServerHandler.OnStart()
func (sh *ServerHandlers) OnStart(serverCTX cwf.ServerContext) {
sh.ServerHandler.OnStart(serverCTX)
}
@ -41,9 +42,9 @@ func (sh *ServerHandlers) CheckOrigin(ctx *fasthttp.RequestCtx) bool {
return true
}
func (sh *ServerHandlers) OnStop() {
func (sh *ServerHandlers) OnStop(serverCTX cwf.ServerContext) {
sh.ServerHandler.OnStop()
sh.ServerHandler.OnStop(serverCTX)
}
func (sh *ServerHandlers) Validate() {

14
servlet/servlet.go Normal file
View File

@ -0,0 +1,14 @@
package servlet
import (
"git.loafle.net/overflow/overflow_gateway_webapp/servlet/web"
oogws "git.loafle.net/overflow/overflow_gateway_websocket/server"
)
func ServletInit(sh oogws.ServerHandler) {
web.ServletInit(sh)
}
func ServletDestroy() {
}

View File

@ -4,27 +4,28 @@ import (
"fmt"
"git.loafle.net/commons_go/logging"
cwf "git.loafle.net/commons_go/websocket_fasthttp"
"git.loafle.net/overflow/overflow_gateway_websocket/config"
"git.loafle.net/overflow/overflow_gateway_websocket/rpc"
jwt "github.com/dgrijalva/jwt-go"
"github.com/valyala/fasthttp"
)
func newRPCGatewayHandler() rpc.RPCGatewayHandler {
gh := &RPCGatewayHandlers{}
func newGatewayRPCHandler() rpc.GatewayRPCHandler {
gh := &GatewayRPCHandlers{}
return gh
}
type RPCGatewayHandlers struct {
rpc.RPCGatewayHandlers
type GatewayRPCHandlers struct {
rpc.GatewayRPCHandlers
}
func (sh *RPCGatewayHandlers) Init() error {
func (sh *GatewayRPCHandlers) Init(serverCTX cwf.ServerContext) error {
return nil
}
func (sh *RPCGatewayHandlers) Handshake(ctx *fasthttp.RequestCtx) (id string, extensionsHeader *fasthttp.ResponseHeader) {
func (sh *GatewayRPCHandlers) Handshake(serverCTX cwf.ServerContext, ctx *fasthttp.RequestCtx) (id string, extensionsHeader *fasthttp.ResponseHeader) {
var ok bool
// tokenString := string(soc.Conn().Headers().Cookie("AuthToken"))
tokenString := "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJvdmVyRmxvdyIsImlhdCI6MTUwNDU5NTExOSwiZXhwIjoxNTM2MTMxMTE5LCJhdWQiOiJ3d3cub3ZlcmZsb3cuY2xvdWQiLCJzdWIiOiJvdmVyZmxvd0Bsb2FmbGUuY29tIn0.-WQi3OykPlJ9x8RcZGhWXEtGw4GhU6wmyJ_AWh2rMeUatQylfPzvmum2Xfp6pwKLMmcP76XoDPNyq06i7RKWNQ"
@ -51,6 +52,6 @@ func (sh *RPCGatewayHandlers) Handshake(ctx *fasthttp.RequestCtx) (id string, ex
return claims["sub"].(string), nil
}
func (sh *RPCGatewayHandlers) Validate() {
sh.RPCGatewayHandlers.Validate()
func (sh *GatewayRPCHandlers) Validate() {
sh.GatewayRPCHandlers.Validate()
}

View File

@ -17,15 +17,19 @@ var (
cfg *oosc.Servlet
)
func Initialize(sh oogws.ServerHandler) {
func ServletInit(sh oogws.ServerHandler) {
cfg = oogwc.Config.Servlets[Name]
if nil == cfg {
logging.Logger().Panic(fmt.Sprintf("Webapp: config of servlet[%s] is not exist", Name))
}
rpcGH := newRPCGatewayHandler()
rpcGH := newGatewayRPCHandler()
rpcSH := sh.RegisterRPCGatewayServlet(Name, rpcGH)
sub := newSubscriberHandler(rpcSH)
sh.RegisterSubscriber(sub)
}
func ServletDestroy() {
}