Skip to content

Commit ace04d5

Browse files
committed
feat(grpcclient): with token header
1 parent 24f091d commit ace04d5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

grpcClient/conn.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"go.uber.org/zap"
1010
"google.golang.org/grpc"
1111
"google.golang.org/grpc/credentials"
12+
"google.golang.org/grpc/metadata"
1213
)
1314

1415
var defaultEndpoint = "gapi.hduhelp.com:443"
@@ -29,3 +30,8 @@ func Conn(ctx context.Context, endpoints ...string) grpc.ClientConnInterface {
2930
}
3031
return conn
3132
}
33+
34+
func WithToken(ctx context.Context, token string) context.Context {
35+
md := metadata.New(map[string]string{"authorization": "token " + token})
36+
return metadata.NewOutgoingContext(ctx, md)
37+
}

0 commit comments

Comments
 (0)