From 502ace5bc19305aec39b1b855b8567d76618cff7 Mon Sep 17 00:00:00 2001 From: nikkiing <1031497516@qq.com> Date: Mon, 15 May 2023 16:45:54 +0800 Subject: [PATCH] metadata --- pkg/meta/metadata.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 pkg/meta/metadata.go 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 "" +}