feat:multi cluster application
This commit is contained in:
6
vendor/openpitrix.io/openpitrix/pkg/util/ctxutil/ctx.go
generated
vendored
6
vendor/openpitrix.io/openpitrix/pkg/util/ctxutil/ctx.go
generated
vendored
@@ -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))
|
||||
}
|
||||
|
||||
25
vendor/openpitrix.io/openpitrix/pkg/util/ctxutil/locale.go
generated
vendored
Normal file
25
vendor/openpitrix.io/openpitrix/pkg/util/ctxutil/locale.go
generated
vendored
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user