ing
This commit is contained in:
parent
b91fc70ae8
commit
74b55942b9
56
constants.go
56
constants.go
|
@ -1,17 +1,71 @@
|
|||
package overflow_gateway_websocket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
cuc "git.loafle.net/commons_go/util/context"
|
||||
)
|
||||
|
||||
var (
|
||||
ServletSocketKey = cuc.ContextKey("ServletSocket")
|
||||
ClientTypeKey = cuc.ContextKey("ClientType")
|
||||
SocketIDKey = cuc.ContextKey("SocketID")
|
||||
TargetIDKey = cuc.ContextKey("TargetID")
|
||||
)
|
||||
|
||||
const (
|
||||
ConfigPathFlagName = "config-dir"
|
||||
ConfigFileName = "config.json"
|
||||
|
||||
GRPCSessionIDKey = "SESSION_ID"
|
||||
GRPCClientTypeKey = "@@OVERFLOW::CLIENT_TYPE"
|
||||
GRPCSessionIDKey = "@@OVERFLOW::SESSION_ID"
|
||||
GRPCTargetIDKey = "@@OVERFLOW::TARGET_ID"
|
||||
)
|
||||
|
||||
type ClientType int
|
||||
|
||||
const (
|
||||
MEMBER ClientType = iota
|
||||
PROBE
|
||||
)
|
||||
|
||||
var (
|
||||
clientTypeID = map[ClientType]string{
|
||||
MEMBER: "MEMBER",
|
||||
PROBE: "PROBE",
|
||||
}
|
||||
|
||||
clientTypeName = map[string]ClientType{
|
||||
"MEMBER": MEMBER,
|
||||
"PROBE": PROBE,
|
||||
}
|
||||
)
|
||||
|
||||
func (ct ClientType) String() string {
|
||||
return clientTypeID[ct]
|
||||
}
|
||||
|
||||
func (ct *ClientType) MarshalJSON() ([]byte, error) {
|
||||
value, ok := clientTypeID[*ct]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Invalid EnumType[%s] value", *ct)
|
||||
}
|
||||
return json.Marshal(value)
|
||||
}
|
||||
|
||||
func (ct *ClientType) UnmarshalJSON(b []byte) error {
|
||||
// unmarshal as string
|
||||
var s string
|
||||
err := json.Unmarshal(b, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
value, ok := clientTypeName[s]
|
||||
if !ok {
|
||||
return fmt.Errorf("Invalid EnumType[%s] value", s)
|
||||
}
|
||||
*ct = value
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -24,7 +24,10 @@ type GatewayRPCServletHandlers struct {
|
|||
}
|
||||
|
||||
func (sh *GatewayRPCServletHandlers) Invoke(servletCTX rpc.ServletContext, requestCodec protocol.RegistryCodec) (result interface{}, err error) {
|
||||
md := metadata.Pairs(oogw.GRPCSessionIDKey, servletCTX.GetAttribute(oogw.SocketIDKey).(string))
|
||||
md := metadata.Pairs(
|
||||
oogw.GRPCClientTypeKey, servletCTX.GetAttribute(oogw.SocketIDKey).(string),
|
||||
oogw.GRPCSessionIDKey, servletCTX.GetAttribute(oogw.SocketIDKey).(string),
|
||||
oogw.GRPCTargetIDKey, servletCTX.GetAttribute(oogw.SocketIDKey).(string))
|
||||
grpcCTX := metadata.NewOutgoingContext(context.Background(), md)
|
||||
|
||||
params, err := requestCodec.Params()
|
||||
|
|
Loading…
Reference in New Issue
Block a user