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/commons_go/logging"
"git.loafle.net/overflow/overflow_gateway_webapp/server" "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" oogws "git.loafle.net/overflow/overflow_gateway_websocket/server"
) )
func main() { func main() {
defer logging.Logger().Sync() defer logging.Logger().Sync()
s := initializeServer() sh := server.NewServerHandler()
servlet.ServletInit(sh)
s := oogws.New(sh)
stop := make(chan os.Signal) stop := make(chan os.Signal)
signal.Notify(stop, syscall.SIGINT) signal.Notify(stop, syscall.SIGINT)
@ -36,12 +39,3 @@ func main() {
s.Stop() 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 package server
import ( import (
cwf "git.loafle.net/commons_go/websocket_fasthttp"
oogws "git.loafle.net/overflow/overflow_gateway_websocket/server" oogws "git.loafle.net/overflow/overflow_gateway_websocket/server"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
) )
@ -17,16 +18,16 @@ type ServerHandlers struct {
// Init invoked before the server is started // Init invoked before the server is started
// If you override ths method, must call // If you override ths method, must call
func (sh *ServerHandlers) Init() error { func (sh *ServerHandlers) Init(serverCTX cwf.ServerContext) error {
if err := sh.ServerHandler.Init(); nil != err { if err := sh.ServerHandler.Init(serverCTX); nil != err {
return err return err
} }
return nil return nil
} }
func (sh *ServerHandlers) OnStart() { func (sh *ServerHandlers) OnStart(serverCTX cwf.ServerContext) {
sh.ServerHandler.OnStart() sh.ServerHandler.OnStart(serverCTX)
} }
@ -41,9 +42,9 @@ func (sh *ServerHandlers) CheckOrigin(ctx *fasthttp.RequestCtx) bool {
return true return true
} }
func (sh *ServerHandlers) OnStop() { func (sh *ServerHandlers) OnStop(serverCTX cwf.ServerContext) {
sh.ServerHandler.OnStop() sh.ServerHandler.OnStop(serverCTX)
} }
func (sh *ServerHandlers) Validate() { 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" "fmt"
"git.loafle.net/commons_go/logging" "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/config"
"git.loafle.net/overflow/overflow_gateway_websocket/rpc" "git.loafle.net/overflow/overflow_gateway_websocket/rpc"
jwt "github.com/dgrijalva/jwt-go" jwt "github.com/dgrijalva/jwt-go"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
) )
func newRPCGatewayHandler() rpc.RPCGatewayHandler { func newGatewayRPCHandler() rpc.GatewayRPCHandler {
gh := &RPCGatewayHandlers{} gh := &GatewayRPCHandlers{}
return gh return gh
} }
type RPCGatewayHandlers struct { type GatewayRPCHandlers struct {
rpc.RPCGatewayHandlers rpc.GatewayRPCHandlers
} }
func (sh *RPCGatewayHandlers) Init() error { func (sh *GatewayRPCHandlers) Init(serverCTX cwf.ServerContext) error {
return nil 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 var ok bool
// tokenString := string(soc.Conn().Headers().Cookie("AuthToken")) // tokenString := string(soc.Conn().Headers().Cookie("AuthToken"))
tokenString := "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJvdmVyRmxvdyIsImlhdCI6MTUwNDU5NTExOSwiZXhwIjoxNTM2MTMxMTE5LCJhdWQiOiJ3d3cub3ZlcmZsb3cuY2xvdWQiLCJzdWIiOiJvdmVyZmxvd0Bsb2FmbGUuY29tIn0.-WQi3OykPlJ9x8RcZGhWXEtGw4GhU6wmyJ_AWh2rMeUatQylfPzvmum2Xfp6pwKLMmcP76XoDPNyq06i7RKWNQ" tokenString := "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJvdmVyRmxvdyIsImlhdCI6MTUwNDU5NTExOSwiZXhwIjoxNTM2MTMxMTE5LCJhdWQiOiJ3d3cub3ZlcmZsb3cuY2xvdWQiLCJzdWIiOiJvdmVyZmxvd0Bsb2FmbGUuY29tIn0.-WQi3OykPlJ9x8RcZGhWXEtGw4GhU6wmyJ_AWh2rMeUatQylfPzvmum2Xfp6pwKLMmcP76XoDPNyq06i7RKWNQ"
@ -51,6 +52,6 @@ func (sh *RPCGatewayHandlers) Handshake(ctx *fasthttp.RequestCtx) (id string, ex
return claims["sub"].(string), nil return claims["sub"].(string), nil
} }
func (sh *RPCGatewayHandlers) Validate() { func (sh *GatewayRPCHandlers) Validate() {
sh.RPCGatewayHandlers.Validate() sh.GatewayRPCHandlers.Validate()
} }

View File

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