feat:multi cluster application

This commit is contained in:
pengcong06
2020-05-25 22:38:03 +08:00
parent d4b7d88b4b
commit 59839439d5
73 changed files with 9838 additions and 6278 deletions

View File

@@ -13,6 +13,7 @@ import (
const (
messageIdKey = "x-message-id"
requestIdKey = "x-request-id"
localeKey = "locale"
)
type getMetadataFromContext func(ctx context.Context) (md metadata.MD, ok bool)
@@ -48,5 +49,8 @@ func GetValueFromContext(ctx context.Context, key string) []string {
}
func Copy(src, dst context.Context) context.Context {
return SetMessageId(dst, GetMessageId(src))
ContextWithSender(dst, GetSender(src))
SetMessageId(dst, GetMessageId(src))
SetRequestId(dst, GetRequestId(src))
return SetLocale(dst, GetLocale(src))
}

View File

@@ -0,0 +1,25 @@
package ctxutil
import (
"context"
"google.golang.org/grpc/metadata"
)
func GetLocale(ctx context.Context) string {
locale := GetValueFromContext(ctx, localeKey)
if len(locale) == 0 {
return ""
}
return locale[0]
}
func SetLocale(ctx context.Context, locale string) context.Context {
ctx = context.WithValue(ctx, localeKey, []string{locale})
md, ok := metadata.FromOutgoingContext(ctx)
if !ok {
md = metadata.MD{}
}
md[localeKey] = []string{locale}
return metadata.NewOutgoingContext(ctx, md)
}