通用包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
utils/pkg/meta/metadata.go

24 lines
477 B

2 years ago
package meta
import (
"context"
"github.com/go-kratos/kratos/v2/metadata"
)
const (
XMdGlobalOperator = "x-md-global-operator"
XMdGlobalAppid = "x-md-global-appid"
XMdServiceName = "x-md-service-name"
)
func Set(ctx context.Context, kv ...string) context.Context {
return metadata.AppendToClientContext(ctx, kv...)
}
func Get(ctx context.Context, key string) string {
if meta, ok := metadata.FromClientContext(ctx); ok {
return meta.Get(key)
}
return ""
}