You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
kratos/transport/grpc/transport.go

66 lines
1.4 KiB

package grpc
import (
"github.com/go-kratos/kratos/v2/transport"
"google.golang.org/grpc/metadata"
)
var _ transport.Transporter = &Transport{}
// Transport is a gRPC transport.
type Transport struct {
endpoint string
operation string
reqHeader headerCarrier
replyHeader headerCarrier
}
// Kind returns the transport kind.
func (tr *Transport) Kind() transport.Kind {
return transport.KindGRPC
}
// Endpoint returns the transport endpoint.
func (tr *Transport) Endpoint() string {
return tr.endpoint
}
// Operation returns the transport operation.
func (tr *Transport) Operation() string {
return tr.operation
}
// RequestHeader returns the request header.
func (tr *Transport) RequestHeader() transport.Header {
return tr.reqHeader
}
// ReplyHeader returns the reply header.
func (tr *Transport) ReplyHeader() transport.Header {
return tr.replyHeader
}
type headerCarrier metadata.MD
// Get returns the value associated with the passed key.
func (mc headerCarrier) Get(key string) string {
vals := metadata.MD(mc).Get(key)
if len(vals) > 0 {
return vals[0]
}
return ""
}
// Set stores the key-value pair.
func (mc headerCarrier) Set(key string, value string) {
metadata.MD(mc).Set(key, value)
}
// Keys lists the keys stored in this carrier.
func (mc headerCarrier) Keys() []string {
keys := make([]string, 0, len(mc))
for k := range metadata.MD(mc) {
keys = append(keys, k)
}
return keys
}