Fixing formatting
This commit is contained in:
parent
5146eb7c3b
commit
564cd5cbbe
64
server.go
64
server.go
|
@ -44,42 +44,42 @@ type RPCResult struct {
|
|||
}
|
||||
|
||||
type RPCServer struct {
|
||||
isDev bool
|
||||
versionHeader string
|
||||
gzipLenThreshold int
|
||||
logger logr.Logger
|
||||
newHandler func(ctx *RPCCtx) IRPCHandler
|
||||
createRPC func(code uint32)(meta.IRPC, error)
|
||||
isDev bool
|
||||
versionHeader string
|
||||
gzipLenThreshold int
|
||||
logger logr.Logger
|
||||
newHandler func(ctx *RPCCtx) IRPCHandler
|
||||
createRPC func(code uint32) (meta.IRPC, error)
|
||||
}
|
||||
|
||||
type IRPCHandler interface {
|
||||
BeforeExecute(p meta.IRPC) error
|
||||
AfterExecute(p meta.IRPC, err error) error
|
||||
Close()
|
||||
Close()
|
||||
}
|
||||
|
||||
type RPCCtx struct {
|
||||
Ctx context.Context
|
||||
Log logr.Logger
|
||||
Log logr.Logger
|
||||
ClientVersion string
|
||||
ClientIP net.IP
|
||||
ClientPlatform int
|
||||
IsDev bool
|
||||
IsDev bool
|
||||
}
|
||||
|
||||
func NewRPCServer(logger logr.Logger,
|
||||
isDev bool,
|
||||
versionHeader string,
|
||||
gzipLenThreshold int,
|
||||
newHandler func(ctx *RPCCtx) IRPCHandler,
|
||||
createRPC func(code uint32)(meta.IRPC, error)) *RPCServer {
|
||||
return &RPCServer{
|
||||
isDev: isDev,
|
||||
versionHeader: versionHeader,
|
||||
gzipLenThreshold : gzipLenThreshold,
|
||||
logger: logger.WithName("[rpc]"),
|
||||
newHandler: newHandler,
|
||||
createRPC: createRPC}
|
||||
isDev bool,
|
||||
versionHeader string,
|
||||
gzipLenThreshold int,
|
||||
newHandler func(ctx *RPCCtx) IRPCHandler,
|
||||
createRPC func(code uint32) (meta.IRPC, error)) *RPCServer {
|
||||
return &RPCServer{
|
||||
isDev: isDev,
|
||||
versionHeader: versionHeader,
|
||||
gzipLenThreshold: gzipLenThreshold,
|
||||
logger: logger.WithName("[rpc]"),
|
||||
newHandler: newHandler,
|
||||
createRPC: createRPC}
|
||||
}
|
||||
|
||||
func (server *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -98,7 +98,7 @@ func (server *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
logger := server.logger
|
||||
logger := server.logger
|
||||
if server.isDev {
|
||||
reqId := uuid.New()
|
||||
logger = logger.WithValues("uid", reqId.String())
|
||||
|
@ -127,7 +127,6 @@ func GetIPStr(r *http.Request) string {
|
|||
return ra
|
||||
}
|
||||
|
||||
|
||||
func (server *RPCServer) writeResponse(canGzip bool, w http.ResponseWriter, payload []byte) {
|
||||
if len(payload) == 0 {
|
||||
server.logger.Error(nil, "Nothing was written to response!")
|
||||
|
@ -166,11 +165,11 @@ func (w *respWriterWithLen) Write(b []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
func (server *RPCServer) serveRequest(context context.Context,
|
||||
logger logr.Logger,
|
||||
request []byte,
|
||||
clientVersion string,
|
||||
clientPlatform int,
|
||||
clientIP net.IP) (result RPCResult) {
|
||||
logger logr.Logger,
|
||||
request []byte,
|
||||
clientVersion string,
|
||||
clientPlatform int,
|
||||
clientIP net.IP) (result RPCResult) {
|
||||
|
||||
result = RPCResult{}
|
||||
|
||||
|
@ -188,8 +187,8 @@ func (server *RPCServer) serveRequest(context context.Context,
|
|||
}
|
||||
}()
|
||||
|
||||
h := server.newHandler(&RPCCtx{context, logger, clientVersion, clientIP, clientPlatform, server.isDev})
|
||||
defer h.Close()
|
||||
h := server.newHandler(&RPCCtx{context, logger, clientVersion, clientIP, clientPlatform, server.isDev})
|
||||
defer h.Close()
|
||||
|
||||
p, err := server.executeRPC(h, request)
|
||||
|
||||
|
@ -206,12 +205,12 @@ func (server *RPCServer) executeRPC(h IRPCHandler, request []byte) (meta.IRPC, e
|
|||
}
|
||||
|
||||
if err := h.BeforeExecute(p); err != nil {
|
||||
err = h.AfterExecute(p, err)
|
||||
err = h.AfterExecute(p, err)
|
||||
//NOTE: returning constructed packet so that it can be inspected
|
||||
return p, err
|
||||
}
|
||||
err = p.Execute(h)
|
||||
err = h.AfterExecute(p, err)
|
||||
err = h.AfterExecute(p, err)
|
||||
|
||||
if err != nil {
|
||||
return p, err
|
||||
|
@ -289,4 +288,3 @@ func parseVersionHeader(header string) (string, int) {
|
|||
|
||||
return cltVersion, cltPlatform
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue