Files
kubesphere/vendor/openpitrix.io/openpitrix/pkg/util/ctxutil/request.go
hongming 1b5681c12b refactor: openpitrix module
Signed-off-by: hongming <talonwan@yunify.com>
2019-09-26 13:41:00 +08:00

30 lines
695 B
Go

// Copyright 2018 The OpenPitrix Authors. All rights reserved.
// Use of this source code is governed by a Apache license
// that can be found in the LICENSE file.
package ctxutil
import (
"context"
"google.golang.org/grpc/metadata"
)
func GetRequestId(ctx context.Context) string {
rid := GetValueFromContext(ctx, requestIdKey)
if len(rid) == 0 {
return ""
}
return rid[0]
}
func SetRequestId(ctx context.Context, requestId string) context.Context {
ctx = context.WithValue(ctx, requestIdKey, []string{requestId})
md, ok := metadata.FromOutgoingContext(ctx)
if !ok {
md = metadata.MD{}
}
md[requestIdKey] = []string{requestId}
return metadata.NewOutgoingContext(ctx, md)
}