You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
508 B
Go
30 lines
508 B
Go
6 years ago
|
package buildid
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"google.golang.org/grpc/metadata"
|
||
|
)
|
||
|
|
||
|
var metadataKey = "buildkit-controlapi-buildid"
|
||
|
|
||
|
func AppendToOutgoingContext(ctx context.Context, id string) context.Context {
|
||
|
if id != "" {
|
||
|
return metadata.AppendToOutgoingContext(ctx, metadataKey, id)
|
||
|
}
|
||
|
return ctx
|
||
|
}
|
||
|
|
||
|
func FromIncomingContext(ctx context.Context) string {
|
||
|
md, ok := metadata.FromIncomingContext(ctx)
|
||
|
if !ok {
|
||
|
return ""
|
||
|
}
|
||
|
|
||
|
if ids := md.Get(metadataKey); len(ids) == 1 {
|
||
|
return ids[0]
|
||
|
}
|
||
|
|
||
|
return ""
|
||
|
}
|