本文整理汇总了Golang中google/golang.org/grpc.SetTrailer函数的典型用法代码示例。如果您正苦于以下问题:Golang SetTrailer函数的具体用法?Golang SetTrailer怎么用?Golang SetTrailer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetTrailer函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SayHello
func (s *server) SayHello(ctx context.Context, in *echo.EchoRequest) (*echo.EchoReply, error) {
log.Println("Got rpc: --> ", in.Name)
log.Println(ctx)
md, ok := metadata.FromContext(ctx)
if ok {
// authorization header from context for oauth2 at client.
// Verify as access_token to oauth2/tokeninfo
// https://developers.google.com/identity/protocols/OAuth2UserAgent#tokeninfo-validation
// https://developers.google.com/identity/protocols/OAuth2ServiceAccount
// -----------------------------------------------------------------------------
// or if the id_token is sent in, verify digital signature
// https://developers.google.com/identity/protocols/OpenIDConnect?hl=en#validatinganidtoken
// https://github.com/golang/oauth2/issues/127
// http://stackoverflow.com/questions/26159658/golang-token-validation-error/26287613#26287613
log.Println(md["authorization"])
//log.Println(md["sal"])
}
var respmdheader = metadata.MD{
"rpc headerKey": []string{"val"},
}
if err := grpc.SendHeader(ctx, respmdheader); err != nil {
log.Fatalf("grpc.SendHeader(%v, %v) = %v, want %v", ctx, respmdheader, err, nil)
}
var respmdfooter = metadata.MD{
"rpc trailerkey": []string{"val"},
}
grpc.SetTrailer(ctx, respmdfooter)
return &echo.EchoReply{Message: "Hello " + in.Name}, nil
}
开发者ID:salrashid123,项目名称:gcegrpc,代码行数:32,代码来源:grpc_server.go
示例2: UnaryCall
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
md, ok := metadata.FromContext(ctx)
if ok {
if err := grpc.SendHeader(ctx, md); err != nil {
grpclog.Fatalf("grpc.SendHeader(%v, %v) = %v, want %v", ctx, md, err, nil)
}
grpc.SetTrailer(ctx, md)
}
if s.security != "" {
// Check Auth info
authInfo, ok := credentials.FromContext(ctx)
if !ok {
grpclog.Fatalf("Failed to get AuthInfo from ctx.")
}
var authType string
switch info := authInfo.(type) {
case credentials.TLSInfo:
authType = info.AuthType()
default:
grpclog.Fatalf("Unknown AuthInfo type")
}
if authType != s.security {
grpclog.Fatalf("Wrong auth type: got %q, want %q", authType, s.security)
}
}
// Simulate some service delay.
time.Sleep(time.Second)
return &testpb.SimpleResponse{
Payload: newPayload(in.GetResponseType(), in.GetResponseSize()),
}, nil
}
开发者ID:johnmccawley,项目名称:origin,代码行数:32,代码来源:end2end_test.go
示例3: EchoBody
func (s *echoServer) EchoBody(ctx context.Context, msg *examples.SimpleMessage) (*examples.SimpleMessage, error) {
glog.Info(msg)
grpc.SendHeader(ctx, metadata.New(map[string]string{
"foo": "foo1",
"bar": "bar1",
}))
grpc.SetTrailer(ctx, metadata.New(map[string]string{
"foo": "foo2",
"bar": "bar2",
}))
return msg, nil
}
开发者ID:tmc,项目名称:grpc-gateway,代码行数:12,代码来源:echo.go
示例4: UnaryCall
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
md, ok := metadata.FromContext(ctx)
if ok {
if err := grpc.SendHeader(ctx, md); err != nil {
grpclog.Fatalf("grpc.SendHeader(%v, %v) = %v, want %v", ctx, md, err, nil)
}
grpc.SetTrailer(ctx, md)
}
// Simulate some service delay.
time.Sleep(time.Second)
return &testpb.SimpleResponse{
Payload: newPayload(in.GetResponseType(), in.GetResponseSize()),
}, nil
}
开发者ID:ELMERzark,项目名称:grpc-go,代码行数:14,代码来源:end2end_test.go
示例5: UnaryCall
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
md, ok := metadata.FromContext(ctx)
if ok {
if err := grpc.SendHeader(ctx, md); err != nil {
return nil, grpc.Errorf(grpc.Code(err), "grpc.SendHeader(_, %v) = %v, want <nil>", md, err)
}
if err := grpc.SetTrailer(ctx, testTrailerMetadata); err != nil {
return nil, grpc.Errorf(grpc.Code(err), "grpc.SetTrailer(_, %v) = %v, want <nil>", testTrailerMetadata, err)
}
}
if in.Id == errorID {
return nil, fmt.Errorf("got error id: %v", in.Id)
}
return &testpb.SimpleResponse{Id: in.Id}, nil
}
开发者ID:tamird,项目名称:grpc-go,代码行数:17,代码来源:stats_test.go
示例6: UnaryCall
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
md, ok := metadata.FromContext(ctx)
if ok {
if err := grpc.SendHeader(ctx, md); err != nil {
return nil, fmt.Errorf("grpc.SendHeader(%v, %v) = %v, want %v", ctx, md, err, nil)
}
grpc.SetTrailer(ctx, md)
}
pr, ok := peer.FromContext(ctx)
if !ok {
return nil, fmt.Errorf("failed to get peer from ctx")
}
if pr.Addr == net.Addr(nil) {
return nil, fmt.Errorf("failed to get peer address")
}
if s.security != "" {
// Check Auth info
var authType, serverName string
switch info := pr.AuthInfo.(type) {
case credentials.TLSInfo:
authType = info.AuthType()
serverName = info.State.ServerName
default:
return nil, fmt.Errorf("Unknown AuthInfo type")
}
if authType != s.security {
return nil, fmt.Errorf("Wrong auth type: got %q, want %q", authType, s.security)
}
if serverName != "x.test.youtube.com" {
return nil, fmt.Errorf("Unknown server name %q", serverName)
}
}
// Simulate some service delay.
time.Sleep(time.Second)
payload, err := newPayload(in.GetResponseType(), in.GetResponseSize())
if err != nil {
return nil, err
}
return &testpb.SimpleResponse{
Payload: payload,
}, nil
}
开发者ID:qyhe,项目名称:grpc_grpc-go,代码行数:45,代码来源:end2end_test.go
示例7: Lookup
func (s *_ABitOfEverythingServer) Lookup(ctx context.Context, msg *sub2.IdMessage) (*examples.ABitOfEverything, error) {
s.m.Lock()
defer s.m.Unlock()
glog.Info(msg)
err := grpc.SendHeader(ctx, metadata.New(map[string]string{
"uuid": msg.Uuid,
}))
if err != nil {
return nil, err
}
if a, ok := s.v[msg.Uuid]; ok {
return a, nil
}
grpc.SetTrailer(ctx, metadata.New(map[string]string{
"foo": "foo2",
"bar": "bar2",
}))
return nil, grpc.Errorf(codes.NotFound, "not found")
}
开发者ID:tmc,项目名称:grpc-gateway,代码行数:22,代码来源:a_bit_of_everything.go
示例8: UnaryCall
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
status := in.GetResponseStatus()
if md, ok := metadata.FromContext(ctx); ok {
if initialMetadata, ok := md[initialMetadataKey]; ok {
header := metadata.Pairs(initialMetadataKey, initialMetadata[0])
grpc.SendHeader(ctx, header)
}
if trailingMetadata, ok := md[trailingMetadataKey]; ok {
trailer := metadata.Pairs(trailingMetadataKey, trailingMetadata[0])
grpc.SetTrailer(ctx, trailer)
}
}
if status != nil && *status.Code != 0 {
return nil, grpc.Errorf(codes.Code(*status.Code), *status.Message)
}
pl, err := serverNewPayload(in.GetResponseType(), in.GetResponseSize())
if err != nil {
return nil, err
}
return &testpb.SimpleResponse{
Payload: pl,
}, nil
}
开发者ID:tamird,项目名称:grpc-go,代码行数:23,代码来源:test_utils.go
示例9: SayHelloStream
func (s *server) SayHelloStream(in *echo.EchoRequest, stream echo.EchoServer_SayHelloStreamServer) error {
log.Println("Got stream: --> ")
ctx := stream.Context()
log.Println(ctx)
var respmdheader = metadata.MD{
"stream headerKey": []string{"val"},
}
if err := grpc.SendHeader(ctx, respmdheader); err != nil {
log.Fatalf("grpc.SendHeader(%v, %v) = %v, want %v", ctx, respmdheader, err, nil)
}
stream.Send(&echo.EchoReply{Message: "Msg1 " + in.Name})
stream.Send(&echo.EchoReply{Message: "Msg2 " + in.Name})
var respmdfooter = metadata.MD{
"stream trailerkey": []string{"val"},
}
grpc.SetTrailer(ctx, respmdfooter)
return nil
}
开发者ID:salrashid123,项目名称:gcegrpc,代码行数:23,代码来源:grpc_server.go
示例10: Ping
func (s *assertingService) Ping(ctx context.Context, ping *pb.PingRequest) (*pb.PingResponse, error) {
// Send user trailers and headers.
grpc.SendHeader(ctx, metadata.Pairs(serverHeaderMdKey, "I like turtles."))
grpc.SetTrailer(ctx, metadata.Pairs(serverTrailerMdKey, "I like ending turtles."))
return &pb.PingResponse{Value: ping.Value, Counter: 42}, nil
}
开发者ID:mwitkow,项目名称:grpc-proxy,代码行数:6,代码来源:proxy_test.go
示例11: Internal_SetCacheControlTrailer
// Internal_SetCacheControlTrailer is an internal func called by the
// code-genned CachedXyzServer wrapper methods. It should not be
// called by user code.
func Internal_SetCacheControlTrailer(ctx context.Context, cc CacheControl) error {
return grpc.SetTrailer(ctx, metadata.MD{"cache-control:max-age": cc.MaxAge.String()})
}
开发者ID:sqs,项目名称:grpccache,代码行数:6,代码来源:cache_control.go
注:本文中的google/golang.org/grpc.SetTrailer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论