ing
This commit is contained in:
parent
6ed6a69d47
commit
2cec996c9d
66
const.go
Normal file
66
const.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
cuc "git.loafle.net/commons/util-go/context"
|
||||
)
|
||||
|
||||
const (
|
||||
SessionGRPCMetadataKey = cuc.ContextKey("SessionGRPCMetadata")
|
||||
SessionClientTypeKey = cuc.ContextKey("SessionClientType")
|
||||
SessionIDKey = cuc.ContextKey("SessionID")
|
||||
SessionTargetIDKey = cuc.ContextKey("SessionTargetID")
|
||||
|
||||
GRPCClientTypeKey = cuc.ContextKey("OVERFLOW_GRPC_CLIENT_TYPE")
|
||||
GRPCSessionIDKey = cuc.ContextKey("OVERFLOW_GRPC_SESSION_ID")
|
||||
GRPCTargetIDKey = cuc.ContextKey("OVERFLOW_GRPC_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
|
||||
}
|
|
@ -7,3 +7,4 @@ import:
|
|||
- package: github.com/gomodule/redigo
|
||||
version: ^2.0.0
|
||||
- package: github.com/segmentio/kafka-go
|
||||
- package: git.loafle.net/commons/util-go
|
||||
|
|
Loading…
Reference in New Issue
Block a user