package transport import ( "context" "net/url" ) type Server interface { Start(context.Context) error Stop(context.Context) error } type Endpointer interface { Endpoint() (*url.URL, error) } type Header interface { Get(key string) string Set(key string, value string) Keys() []string } type Transporter interface { Kind() Kind Endpoint() string Operation() string RequestHeader() Header ReplyHeader() Header } type Kind string func (k Kind) String() string { return string(k) } const ( KindGRPC Kind = "grpc" KindHTTP Kind = "http" ) type ( serverTransportKey struct{} clientTransportKey struct{} ) func NewServerContext(ctx context.Context, tr Transporter) context.Context { return context.WithValue(ctx, serverTransportKey{}, tr) } func FromServerContext(ctx context.Context) (tr Transporter, ok bool) { tr, ok = ctx.Value(serverTransportKey{}).(Transporter) return } func NewClientContext(ctx context.Context, tr Transporter) context.Context { return context.WithValue(ctx, clientTransportKey{}, tr) } func FromClientContext(ctx context.Context) (tr Transporter, ok bool) { tr, ok = ctx.Value(clientTransportKey{}).(Transporter) return }