echo

package
v0.0.0-...-05d1c7e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2021 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func ContextValuesToGRPCMetadata

func ContextValuesToGRPCMetadata(keys []string) grpctransport.ClientRequestFunc

ContextValuesToGRPCMetadata is a grpctransport.ClientRequestFunc

func CtxValuesToSend

func CtxValuesToSend(keys ...string) httptransport.ClientOption

CtxValuesToSend configures the http client to pull the specified keys out of the context and add them to the http request as headers. Note that keys will have net/http.CanonicalHeaderKey called on them before being send over the wire and that is the form they will be available in the server context.

func DecodeGRPCEchoRequest

func DecodeGRPCEchoRequest(_ context.Context, grpcReq interface{}) (interface{}, error)

DecodeGRPCEchoRequest is a transport/grpc.DecodeRequestFunc that converts a gRPC echo request to a user-domain echo request. Primarily useful in a server.

func DecodeGRPCEchoResponse

func DecodeGRPCEchoResponse(_ context.Context, grpcReply interface{}) (interface{}, error)

DecodeGRPCEchoResponse is a transport/grpc.DecodeResponseFunc that converts a gRPC echo reply to a user-domain echo response. Primarily useful in a client.

func DecodeGRPCLouderGetRequest

func DecodeGRPCLouderGetRequest(_ context.Context, grpcReq interface{}) (interface{}, error)

DecodeGRPCLouderGetRequest is a transport/grpc.DecodeRequestFunc that converts a gRPC louderget request to a user-domain louderget request. Primarily useful in a server.

func DecodeGRPCLouderGetResponse

func DecodeGRPCLouderGetResponse(_ context.Context, grpcReply interface{}) (interface{}, error)

DecodeGRPCLouderGetResponse is a transport/grpc.DecodeResponseFunc that converts a gRPC louderget reply to a user-domain louderget response. Primarily useful in a client.

func DecodeGRPCLouderRequest

func DecodeGRPCLouderRequest(_ context.Context, grpcReq interface{}) (interface{}, error)

DecodeGRPCLouderRequest is a transport/grpc.DecodeRequestFunc that converts a gRPC louder request to a user-domain louder request. Primarily useful in a server.

func DecodeGRPCLouderResponse

func DecodeGRPCLouderResponse(_ context.Context, grpcReply interface{}) (interface{}, error)

DecodeGRPCLouderResponse is a transport/grpc.DecodeResponseFunc that converts a gRPC louder reply to a user-domain louder response. Primarily useful in a client.

func DecodeHTTPEchoResponse

func DecodeHTTPEchoResponse(_ context.Context, r *http.Response) (interface{}, error)

DecodeHTTPEchoResponse is a transport/http.DecodeResponseFunc that decodes a JSON-encoded EchoResponse response from the HTTP response body. If the response has a non-200 status code, we will interpret that as an error and attempt to decode the specific error message from the response body. Primarily useful in a client.

func DecodeHTTPEchoZeroRequest

func DecodeHTTPEchoZeroRequest(_ context.Context, r *http.Request) (interface{}, error)

DecodeHTTPEchoZeroRequest is a transport/http.DecodeRequestFunc that decodes a JSON-encoded echo request from the HTTP request body. Primarily useful in a server.

func DecodeHTTPLouderGetResponse

func DecodeHTTPLouderGetResponse(_ context.Context, r *http.Response) (interface{}, error)

DecodeHTTPLouderGetResponse is a transport/http.DecodeResponseFunc that decodes a JSON-encoded EchoResponse response from the HTTP response body. If the response has a non-200 status code, we will interpret that as an error and attempt to decode the specific error message from the response body. Primarily useful in a client.

func DecodeHTTPLouderGetZeroRequest

func DecodeHTTPLouderGetZeroRequest(_ context.Context, r *http.Request) (interface{}, error)

DecodeHTTPLouderGetZeroRequest is a transport/http.DecodeRequestFunc that decodes a JSON-encoded louderget request from the HTTP request body. Primarily useful in a server.

func DecodeHTTPLouderOneRequest

func DecodeHTTPLouderOneRequest(_ context.Context, r *http.Request) (interface{}, error)

DecodeHTTPLouderOneRequest is a transport/http.DecodeRequestFunc that decodes a JSON-encoded louder request from the HTTP request body. Primarily useful in a server.

func DecodeHTTPLouderResponse

func DecodeHTTPLouderResponse(_ context.Context, r *http.Response) (interface{}, error)

DecodeHTTPLouderResponse is a transport/http.DecodeResponseFunc that decodes a JSON-encoded EchoResponse response from the HTTP response body. If the response has a non-200 status code, we will interpret that as an error and attempt to decode the specific error message from the response body. Primarily useful in a client.

func DecodeHTTPLouderZeroRequest

func DecodeHTTPLouderZeroRequest(_ context.Context, r *http.Request) (interface{}, error)

DecodeHTTPLouderZeroRequest is a transport/http.DecodeRequestFunc that decodes a JSON-encoded louder request from the HTTP request body. Primarily useful in a server.

func DecodeNATSEchoRequest

func DecodeNATSEchoRequest(ctx context.Context, msg *nats.Msg) (interface{}, error)

func DecodeNATSEchoResponse

func DecodeNATSEchoResponse(ctx context.Context, msg *nats.Msg) (interface{}, error)

DecodeNATSEchoResponse is a transport/nats.DecodeResponseFunc that converts a nats.Msg to a user-domain echo response. Primarily useful in a client.

func DecodeNATSLouderGetRequest

func DecodeNATSLouderGetRequest(ctx context.Context, msg *nats.Msg) (interface{}, error)

func DecodeNATSLouderGetResponse

func DecodeNATSLouderGetResponse(ctx context.Context, msg *nats.Msg) (interface{}, error)

DecodeNATSLouderGetResponse is a transport/nats.DecodeResponseFunc that converts a nats.Msg to a user-domain louderget response. Primarily useful in a client.

func DecodeNATSLouderRequest

func DecodeNATSLouderRequest(ctx context.Context, msg *nats.Msg) (interface{}, error)

func DecodeNATSLouderResponse

func DecodeNATSLouderResponse(ctx context.Context, msg *nats.Msg) (interface{}, error)

DecodeNATSLouderResponse is a transport/nats.DecodeResponseFunc that converts a nats.Msg to a user-domain louder response. Primarily useful in a client.

func EncodeGRPCEchoRequest

func EncodeGRPCEchoRequest(_ context.Context, request interface{}) (interface{}, error)

EncodeGRPCEchoRequest is a transport/grpc.EncodeRequestFunc that converts a user-domain echo request to a gRPC echo request. Primarily useful in a client.

func EncodeGRPCEchoResponse

func EncodeGRPCEchoResponse(_ context.Context, response interface{}) (interface{}, error)

EncodeGRPCEchoResponse is a transport/grpc.EncodeResponseFunc that converts a user-domain echo response to a gRPC echo reply. Primarily useful in a server.

func EncodeGRPCLouderGetRequest

func EncodeGRPCLouderGetRequest(_ context.Context, request interface{}) (interface{}, error)

EncodeGRPCLouderGetRequest is a transport/grpc.EncodeRequestFunc that converts a user-domain louderget request to a gRPC louderget request. Primarily useful in a client.

func EncodeGRPCLouderGetResponse

func EncodeGRPCLouderGetResponse(_ context.Context, response interface{}) (interface{}, error)

EncodeGRPCLouderGetResponse is a transport/grpc.EncodeResponseFunc that converts a user-domain louderget response to a gRPC louderget reply. Primarily useful in a server.

func EncodeGRPCLouderRequest

func EncodeGRPCLouderRequest(_ context.Context, request interface{}) (interface{}, error)

EncodeGRPCLouderRequest is a transport/grpc.EncodeRequestFunc that converts a user-domain louder request to a gRPC louder request. Primarily useful in a client.

func EncodeGRPCLouderResponse

func EncodeGRPCLouderResponse(_ context.Context, response interface{}) (interface{}, error)

EncodeGRPCLouderResponse is a transport/grpc.EncodeResponseFunc that converts a user-domain louder response to a gRPC louder reply. Primarily useful in a server.

func EncodeHTTPEchoZeroRequest

func EncodeHTTPEchoZeroRequest(_ context.Context, r *http.Request, request interface{}) error

EncodeHTTPEchoZeroRequest is a transport/http.EncodeRequestFunc that encodes a echo request into the various portions of the http request (path, query, and body).

func EncodeHTTPGenericResponse

func EncodeHTTPGenericResponse(_ context.Context, w http.ResponseWriter, response interface{}) error

EncodeHTTPGenericResponse is a transport/http.EncodeResponseFunc that encodes the response as JSON to the response writer. Primarily useful in a server.

func EncodeHTTPLouderGetZeroRequest

func EncodeHTTPLouderGetZeroRequest(_ context.Context, r *http.Request, request interface{}) error

EncodeHTTPLouderGetZeroRequest is a transport/http.EncodeRequestFunc that encodes a louderget request into the various portions of the http request (path, query, and body).

func EncodeHTTPLouderOneRequest

func EncodeHTTPLouderOneRequest(_ context.Context, r *http.Request, request interface{}) error

that encodes a louder request into the various portions of the http request (path, query, and body).

func EncodeHTTPLouderZeroRequest

func EncodeHTTPLouderZeroRequest(_ context.Context, r *http.Request, request interface{}) error

EncodeHTTPLouderZeroRequest is a transport/http.EncodeRequestFunc that encodes a louder request into the various portions of the http request (path, query, and body).

func EncodeNATSGenericRequest

func EncodeNATSGenericRequest(ctx context.Context, msg *nats.Msg, request interface{}) error

NATS Client Encode EncodeNATSGenericRequest is a transport/nats.EncodeRequestFunc that serializes the request as a JSON object to the Data of the Msg. Many JSON-over-NATS services can use it as a sensible default.

func EncodeNATSGenericResponse

func EncodeNATSGenericResponse(ctx context.Context, reply string, nc *nats.Conn, response interface{}) error

EncodeNATSGenericResponse is a transport/nats.EncodeResponseFunc that encodes JSON object to the subscriber reply. Many JSON-over services can use it as a sensible default.

func GRPCMetadataToContext

func GRPCMetadataToContext(ctx context.Context, md metadata.MD) context.Context

func HTTPHeadersToContext

func HTTPHeadersToContext(ctx context.Context, r *http.Request) context.Context

func MakeEchoEndpoint

func MakeEchoEndpoint(s EchoServer) endpoint.Endpoint

func MakeHTTPHandler

func MakeHTTPHandler(endpoints Endpoints, options ...httptransport.ServerOption) http.Handler

MakeHTTPHandler returns a handler that makes a set of endpoints available on predefined paths.

func MakeLouderEndpoint

func MakeLouderEndpoint(s EchoServer) endpoint.Endpoint

func MakeLouderGetEndpoint

func MakeLouderGetEndpoint(s EchoServer) endpoint.Endpoint

func MakeNATSServer

func MakeNATSServer(endpoints Endpoints, options ...natstransport.SubscriberOption) *natsServer

MakeNATSServer makes a set of endpoints available as a NATS EchoServer.

func RegisterEchoServer

func RegisterEchoServer(s grpc.ServiceRegistrar, srv EchoServer)

func ServeNATS

func ServeNATS(conn *nats.Conn, srv *natsServer) error

ServeNATS

Types

type EchoClient

type EchoClient interface {
	// Echo "echos" the incoming string
	Echo(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (*EchoResponse, error)
	// Louder "echos" the incoming string with `Loudness` additional exclamation marks
	Louder(ctx context.Context, in *LouderRequest, opts ...grpc.CallOption) (*EchoResponse, error)
	// LouderGet is the same as Louder, but pulls fields other than Loudness (i.e. In) from query params instead of POST
	LouderGet(ctx context.Context, in *LouderRequest, opts ...grpc.CallOption) (*EchoResponse, error)
}

EchoClient is the client API for Echo service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewEchoClient

func NewEchoClient(cc grpc.ClientConnInterface) EchoClient

type EchoRequest

type EchoRequest struct {
	In           string                  `protobuf:"bytes,1,opt,name=in,proto3" json:"in,omitempty"`
	At           *int64                  `protobuf:"varint,2,opt,name=at,proto3,oneof" json:"at,omitempty"`
	Desc         *string                 `protobuf:"bytes,3,opt,name=desc,proto3,oneof" json:"desc,omitempty"`
	Debug        *bool                   `protobuf:"varint,4,opt,name=debug,proto3,oneof" json:"debug,omitempty"`
	Others       []string                `protobuf:"bytes,5,rep,name=others,proto3" json:"others,omitempty"`
	JsonStr      *wrapperspb.StringValue `protobuf:"bytes,6,opt,name=json_str,json=jsonStr,proto3" json:"json_str,omitempty"`
	JsonInt64    *wrapperspb.Int64Value  `protobuf:"bytes,7,opt,name=json_int64,json=jsonInt64,proto3" json:"json_int64,omitempty"`
	Message      *Msg                    `protobuf:"bytes,9,opt,name=message,proto3" json:"message,omitempty"`
	CreatedAt    *timestamppb.Timestamp  `protobuf:"bytes,10,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
	AnyData      *anypb.Any              `protobuf:"bytes,11,opt,name=any_data,json=anyData,proto3" json:"any_data,omitempty"`
	StructData   *structpb.Struct        `protobuf:"bytes,12,opt,name=struct_data,json=structData,proto3" json:"struct_data,omitempty"`
	EmptyData    *emptypb.Empty          `protobuf:"bytes,13,opt,name=empty_data,json=emptyData,proto3" json:"empty_data,omitempty"`
	DurationData *durationpb.Duration    `protobuf:"bytes,14,opt,name=duration_data,json=durationData,proto3" json:"duration_data,omitempty"`
	MaskData     *fieldmaskpb.FieldMask  `protobuf:"bytes,15,opt,name=mask_data,json=maskData,proto3" json:"mask_data,omitempty"`
	// contains filtered or unexported fields
}

func (*EchoRequest) Descriptor deprecated

func (*EchoRequest) Descriptor() ([]byte, []int)

Deprecated: Use EchoRequest.ProtoReflect.Descriptor instead.

func (*EchoRequest) GetAnyData

func (x *EchoRequest) GetAnyData() *anypb.Any

func (*EchoRequest) GetAt

func (x *EchoRequest) GetAt() int64

func (*EchoRequest) GetCreatedAt

func (x *EchoRequest) GetCreatedAt() *timestamppb.Timestamp

func (*EchoRequest) GetDebug

func (x *EchoRequest) GetDebug() bool

func (*EchoRequest) GetDesc

func (x *EchoRequest) GetDesc() string

func (*EchoRequest) GetDurationData

func (x *EchoRequest) GetDurationData() *durationpb.Duration

func (*EchoRequest) GetEmptyData

func (x *EchoRequest) GetEmptyData() *emptypb.Empty

func (*EchoRequest) GetIn

func (x *EchoRequest) GetIn() string

func (*EchoRequest) GetJsonInt64

func (x *EchoRequest) GetJsonInt64() *wrapperspb.Int64Value

func (*EchoRequest) GetJsonStr

func (x *EchoRequest) GetJsonStr() *wrapperspb.StringValue

func (*EchoRequest) GetMaskData

func (x *EchoRequest) GetMaskData() *fieldmaskpb.FieldMask

func (*EchoRequest) GetMessage

func (x *EchoRequest) GetMessage() *Msg

func (*EchoRequest) GetOthers

func (x *EchoRequest) GetOthers() []string

func (*EchoRequest) GetStructData

func (x *EchoRequest) GetStructData() *structpb.Struct

func (*EchoRequest) ProtoMessage

func (*EchoRequest) ProtoMessage()

func (*EchoRequest) ProtoReflect

func (x *EchoRequest) ProtoReflect() protoreflect.Message

func (*EchoRequest) Reset

func (x *EchoRequest) Reset()

func (*EchoRequest) String

func (x *EchoRequest) String() string

type EchoResponse

type EchoResponse struct {
	Out       string                 `protobuf:"bytes,1,opt,name=out,proto3" json:"out,omitempty"`
	CreatedAt *timestamppb.Timestamp `protobuf:"bytes,9,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
	// contains filtered or unexported fields
}

func (*EchoResponse) Descriptor deprecated

func (*EchoResponse) Descriptor() ([]byte, []int)

Deprecated: Use EchoResponse.ProtoReflect.Descriptor instead.

func (*EchoResponse) GetCreatedAt

func (x *EchoResponse) GetCreatedAt() *timestamppb.Timestamp

func (*EchoResponse) GetOut

func (x *EchoResponse) GetOut() string

func (*EchoResponse) ProtoMessage

func (*EchoResponse) ProtoMessage()

func (*EchoResponse) ProtoReflect

func (x *EchoResponse) ProtoReflect() protoreflect.Message

func (*EchoResponse) Reset

func (x *EchoResponse) Reset()

func (*EchoResponse) String

func (x *EchoResponse) String() string

type EchoServer

type EchoServer interface {
	// Echo "echos" the incoming string
	Echo(context.Context, *EchoRequest) (*EchoResponse, error)
	// Louder "echos" the incoming string with `Loudness` additional exclamation marks
	Louder(context.Context, *LouderRequest) (*EchoResponse, error)
	// LouderGet is the same as Louder, but pulls fields other than Loudness (i.e. In) from query params instead of POST
	LouderGet(context.Context, *LouderRequest) (*EchoResponse, error)
	// contains filtered or unexported methods
}

EchoServer is the server API for Echo service. All implementations must embed UnimplementedEchoServer for forward compatibility

func MakeGRPCServer

func MakeGRPCServer(endpoints Endpoints, options ...grpctransport.ServerOption) EchoServer

MakeGRPCServer makes a set of endpoints available as a gRPC EchoServer.

func NewGRPCClient

func NewGRPCClient(conn *grpc.ClientConn, options ...grpctransport.ClientOption) (EchoServer, error)

NewGRPCClient returns an service backed by a gRPC client connection. It is the responsibility of the caller to dial, and later close, the connection.

func NewHTTPClient

func NewHTTPClient(instance string, options ...httptransport.ClientOption) (EchoServer, error)

NewHTTPClient returns a service backed by an HTTP server living at the remote instance. We expect instance to come from a service discovery system, so likely of the form "host:port".

func NewNATSClient

func NewNATSClient(conn *nats.Conn, options ...natstransport.PublisherOption) (EchoServer, error)

NewNATSClient returns an service backed by a nats client connection. It is the responsibility of the caller to dial, and later close, the connection.

type Endpoints

type Endpoints struct {
	UnimplementedEchoServer

	EchoEndpoint endpoint.Endpoint

	LouderEndpoint endpoint.Endpoint

	LouderGetEndpoint endpoint.Endpoint
}

In a server, it's useful for functions that need to operate on a per-endpoint basis. For example, you might pass an Endpoints to a function that produces an http.Handler, with each method (endpoint) wired up to a specific path. (It is probably a mistake in design to invoke the Service methods on the Endpoints struct in a server.)

In a client, it's useful to collect individually constructed endpoints into a single type that implements the Service interface. For example, you might construct individual endpoints using transport/http.NewClient, combine them into an Endpoints, and return it to the caller as a Service.

func (Endpoints) Echo

func (e Endpoints) Echo(ctx context.Context, in *EchoRequest) (*EchoResponse, error)

func (Endpoints) Louder

func (e Endpoints) Louder(ctx context.Context, in *LouderRequest) (*EchoResponse, error)

func (Endpoints) LouderGet

func (e Endpoints) LouderGet(ctx context.Context, in *LouderRequest) (*EchoResponse, error)

func (*Endpoints) WrapAllExcept

func (e *Endpoints) WrapAllExcept(middleware endpoint.Middleware, excluded ...string)

WrapAllExcept wraps each Endpoint field of struct Endpoints with a go-kit/kit/endpoint.Middleware. Use this for applying a set of middlewares to every endpoint in the service. Optionally, endpoints can be passed in by name to be excluded from being wrapped. WrapAllExcept(middleware, "Status", "Ping")

func (*Endpoints) WrapAllLabeledExcept

func (e *Endpoints) WrapAllLabeledExcept(middleware func(string, endpoint.Endpoint) endpoint.Endpoint, excluded ...string)

WrapAllLabeledExcept wraps each Endpoint field of struct Endpoints with a LabeledMiddleware, which will receive the name of the endpoint. See LabeldMiddleware. See method WrapAllExept for details on excluded functionality.

type LabeledMiddleware

type LabeledMiddleware func(string, endpoint.Endpoint) endpoint.Endpoint

LabeledMiddleware will get passed the endpoint name when passed to WrapAllLabeledExcept, this can be used to write a generic metrics middleware which can send the endpoint name to the metrics collector.

type LouderRequest

type LouderRequest struct {

	// in is the string to echo back
	In string `protobuf:"bytes,1,opt,name=in,proto3" json:"in,omitempty"`
	// loudness is the number of exclamations marks to add to the echoed string
	Loudness int32 `protobuf:"varint,2,opt,name=loudness,proto3" json:"loudness,omitempty"`
	// contains filtered or unexported fields
}

func (*LouderRequest) Descriptor deprecated

func (*LouderRequest) Descriptor() ([]byte, []int)

Deprecated: Use LouderRequest.ProtoReflect.Descriptor instead.

func (*LouderRequest) GetIn

func (x *LouderRequest) GetIn() string

func (*LouderRequest) GetLoudness

func (x *LouderRequest) GetLoudness() int32

func (*LouderRequest) ProtoMessage

func (*LouderRequest) ProtoMessage()

func (*LouderRequest) ProtoReflect

func (x *LouderRequest) ProtoReflect() protoreflect.Message

func (*LouderRequest) Reset

func (x *LouderRequest) Reset()

func (*LouderRequest) String

func (x *LouderRequest) String() string

type Msg

type Msg struct {
	Code int32  `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Msg  string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"`
	// contains filtered or unexported fields
}

func (*Msg) Descriptor deprecated

func (*Msg) Descriptor() ([]byte, []int)

Deprecated: Use Msg.ProtoReflect.Descriptor instead.

func (*Msg) GetCode

func (x *Msg) GetCode() int32

func (*Msg) GetMsg

func (x *Msg) GetMsg() string

func (*Msg) ProtoMessage

func (*Msg) ProtoMessage()

func (*Msg) ProtoReflect

func (x *Msg) ProtoReflect() protoreflect.Message

func (*Msg) Reset

func (x *Msg) Reset()

func (*Msg) String

func (x *Msg) String() string

type UnimplementedEchoServer

type UnimplementedEchoServer struct {
}

UnimplementedEchoServer must be embedded to have forward compatible implementations.

func (UnimplementedEchoServer) Echo

func (UnimplementedEchoServer) Louder

func (UnimplementedEchoServer) LouderGet

type UnsafeEchoServer

type UnsafeEchoServer interface {
	// contains filtered or unexported methods
}

UnsafeEchoServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to EchoServer will result in compilation errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL