diff --git a/pkg/meta/metadata.go b/pkg/meta/metadata.go new file mode 100644 index 0000000..d648339 --- /dev/null +++ b/pkg/meta/metadata.go @@ -0,0 +1,23 @@ +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 "" +}