Documentation
¶
Index ¶
- Constants
- Variables
- func WriteError(resp http.ResponseWriter, err error)
- type EchoRequest
- type EchoResponse
- func (*EchoResponse) Descriptor() ([]byte, []int)deprecated
- func (x *EchoResponse) GetLogMetadata() map[string]string
- func (x *EchoResponse) GetMessage() string
- func (x *EchoResponse) GetSubject() string
- func (*EchoResponse) ProtoMessage()
- func (x *EchoResponse) ProtoReflect() protoreflect.Message
- func (x *EchoResponse) Reset()
- func (x *EchoResponse) String() string
- type FailRequest
- type FailResponse
- type HTTPClient
- type Test
- type TwirpServer
Constants ¶
const TestPathPrefix = "/twirp/elephantine.testservice.v1.Test/"
TestPathPrefix is a convenience constant that may identify URL paths. Should be used with caution, it only matches routes generated by Twirp Go clients, with the default "/twirp" prefix and default CamelCase service and method names. More info: https://twitchtv.github.io/twirp/docs/routing.html
Variables ¶
var File_internal_testservice_testservice_proto protoreflect.FileDescriptor
Functions ¶
func WriteError ¶
func WriteError(resp http.ResponseWriter, err error)
WriteError writes an HTTP response with a valid Twirp error format (code, msg, meta). Useful outside of the Twirp server (e.g. http middleware), but does not trigger hooks. If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err)
Types ¶
type EchoRequest ¶
type EchoRequest struct {
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
// contains filtered or unexported fields
}
func (*EchoRequest) Descriptor
deprecated
func (*EchoRequest) Descriptor() ([]byte, []int)
Deprecated: Use EchoRequest.ProtoReflect.Descriptor instead.
func (*EchoRequest) GetMessage ¶
func (x *EchoRequest) GetMessage() string
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 {
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
Subject string `protobuf:"bytes,2,opt,name=subject,proto3" json:"subject,omitempty"`
// log_metadata is what the service could see of the request log metadata,
// which is what the parity tests compare between the two stacks.
LogMetadata map[string]string `` /* 168-byte string literal not displayed */
// contains filtered or unexported fields
}
func (*EchoResponse) Descriptor
deprecated
func (*EchoResponse) Descriptor() ([]byte, []int)
Deprecated: Use EchoResponse.ProtoReflect.Descriptor instead.
func (*EchoResponse) GetLogMetadata ¶
func (x *EchoResponse) GetLogMetadata() map[string]string
func (*EchoResponse) GetMessage ¶
func (x *EchoResponse) GetMessage() string
func (*EchoResponse) GetSubject ¶
func (x *EchoResponse) GetSubject() 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 FailRequest ¶
type FailRequest struct {
Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
// contains filtered or unexported fields
}
func (*FailRequest) Descriptor
deprecated
func (*FailRequest) Descriptor() ([]byte, []int)
Deprecated: Use FailRequest.ProtoReflect.Descriptor instead.
func (*FailRequest) GetCode ¶
func (x *FailRequest) GetCode() string
func (*FailRequest) ProtoMessage ¶
func (*FailRequest) ProtoMessage()
func (*FailRequest) ProtoReflect ¶
func (x *FailRequest) ProtoReflect() protoreflect.Message
func (*FailRequest) Reset ¶
func (x *FailRequest) Reset()
func (*FailRequest) String ¶
func (x *FailRequest) String() string
type FailResponse ¶
type FailResponse struct {
// contains filtered or unexported fields
}
func (*FailResponse) Descriptor
deprecated
func (*FailResponse) Descriptor() ([]byte, []int)
Deprecated: Use FailResponse.ProtoReflect.Descriptor instead.
func (*FailResponse) ProtoMessage ¶
func (*FailResponse) ProtoMessage()
func (*FailResponse) ProtoReflect ¶
func (x *FailResponse) ProtoReflect() protoreflect.Message
func (*FailResponse) Reset ¶
func (x *FailResponse) Reset()
func (*FailResponse) String ¶
func (x *FailResponse) String() string
type HTTPClient ¶
HTTPClient is the interface used by generated clients to send HTTP requests. It is fulfilled by *(net/http).Client, which is sufficient for most users. Users can provide their own implementation for special retry policies.
HTTPClient implementations should not follow redirects. Redirects are automatically disabled if *(net/http).Client is passed to client constructors. See the withoutRedirects function in this file for more details.
type Test ¶
type Test interface {
// Echo returns the message it was given, together with what the service
// could see of the caller.
Echo(context.Context, *EchoRequest) (*EchoResponse, error)
// Fail returns an error with the requested code and error metadata.
Fail(context.Context, *FailRequest) (*FailResponse, error)
}
Test is the fixture service the dual-stack tests in the rpc package are run against. It is generated with the same plugins and versions the fleet generates its services with.
func NewTestJSONClient ¶
func NewTestJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) Test
NewTestJSONClient creates a JSON client that implements the Test interface. It communicates using JSON and can be configured with a custom HTTPClient.
func NewTestProtobufClient ¶
func NewTestProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) Test
NewTestProtobufClient creates a Protobuf client that implements the Test interface. It communicates using Protobuf and can be configured with a custom HTTPClient.
type TwirpServer ¶
type TwirpServer interface {
http.Handler
// ServiceDescriptor returns gzipped bytes describing the .proto file that
// this service was generated from. Once unzipped, the bytes can be
// unmarshalled as a
// google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto.
//
// The returned integer is the index of this particular service within that
// FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a
// low-level field, expected to be used for reflection.
ServiceDescriptor() ([]byte, int)
// ProtocGenTwirpVersion is the semantic version string of the version of
// twirp used to generate this file.
ProtocGenTwirpVersion() string
// PathPrefix returns the HTTP URL path prefix for all methods handled by this
// service. This can be used with an HTTP mux to route Twirp requests.
// The path prefix is in the form: "/<prefix>/<package>.<Service>/"
// that is, everything in a Twirp route except for the <Method> at the end.
PathPrefix() string
}
TwirpServer is the interface generated server structs will support: they're HTTP handlers with additional methods for accessing metadata about the service. Those accessors are a low-level API for building reflection tools. Most people can think of TwirpServers as just http.Handlers.
func NewTestServer ¶
func NewTestServer(svc Test, opts ...interface{}) TwirpServer
NewTestServer builds a TwirpServer that can be used as an http.Handler to handle HTTP requests that are routed to the right method in the provided svc implementation. The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks).