overflow_gateway_websocket/constants.go

74 lines
1.3 KiB
Go
Raw Normal View History

2017-11-10 13:24:10 +00:00
package overflow_gateway_websocket
import (
2018-03-19 07:11:21 +00:00
"encoding/json"
"fmt"
2017-11-14 05:57:03 +00:00
cuc "git.loafle.net/commons_go/util/context"
2017-11-10 13:24:10 +00:00
)
var (
2017-11-28 10:40:45 +00:00
ServletSocketKey = cuc.ContextKey("ServletSocket")
2018-03-19 07:19:34 +00:00
GRPCMetadataKey = cuc.ContextKey("GRPCMetadata")
ClientTypeKey = cuc.ContextKey("ClientType")
SocketIDKey = cuc.ContextKey("SocketID")
TargetIDKey = cuc.ContextKey("TargetID")
2017-11-10 13:24:10 +00:00
)
const (
ConfigPathFlagName = "config-dir"
ConfigFileName = "config.json"
2017-11-14 05:57:03 +00:00
2018-03-19 07:57:56 +00:00
GRPCClientTypeKey = "OVERFLOW_GRPC_CLIENT_TYPE"
GRPCSessionIDKey = "OVERFLOW_GRPC_SESSION_ID"
GRPCTargetIDKey = "OVERFLOW_GRPC_TARGET_ID"
2017-11-10 13:24:10 +00:00
)
2018-03-19 07:11:21 +00:00
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
}