twirper

package
v0.0.0-...-a603bc5 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package twirper is a generated protocol buffer package.

It is generated from these files:

twirper.proto

It has these top-level messages:

EchoReq
RepeatReq
RepeatResp

Package twirper is a generated twirp stub package. This code was generated with github.com/twitchtv/twirp/protoc-gen-twirp v5.3.0.

It is generated from these files:

twirper.proto

Index

Constants

View Source
const TwirperPathPrefix = "/twirp/twirper.Twirper/"

TwirperPathPrefix is used for all URL paths on a twirp Twirper server. Requests are always: POST TwirperPathPrefix/method It can be used in an HTTP mux to route twirp requests along with non-twirp requests on other routes.

Variables

This section is empty.

Functions

func WriteError

func WriteError(resp http.ResponseWriter, err error)

WriteError writes an HTTP response with a valid Twirp error format. If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err)

Types

type EchoReq

type EchoReq struct {
	// Message will be echoed back in the EchoResp
	Message string `protobuf:"bytes,1,opt,name=Message" json:"Message,omitempty"`
}

Request type for the Echo RPC (also the response, because echo)

func (*EchoReq) Descriptor

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

func (*EchoReq) GetMessage

func (m *EchoReq) GetMessage() string

func (*EchoReq) ProtoMessage

func (*EchoReq) ProtoMessage()

func (*EchoReq) Reset

func (m *EchoReq) Reset()

func (*EchoReq) String

func (m *EchoReq) String() string

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

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 RepeatReq

type RepeatReq struct {
	// Message to be repeated
	Message string `protobuf:"bytes,1,opt,name=Message" json:"Message,omitempty"`
	// The number of times to repeat the message
	NumRepeats int32 `protobuf:"varint,2,opt,name=NumRepeats" json:"NumRepeats,omitempty"`
	// Milliseconds to wait between repeats
	DelayMs int64 `protobuf:"varint,3,opt,name=DelayMs" json:"DelayMs,omitempty"`
	// Send an error after this many messages (no errors if ErrAfter<=0)
	ErrAfter int32 `protobuf:"varint,4,opt,name=ErrAfter" json:"ErrAfter,omitempty"`
}

func (*RepeatReq) Descriptor

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

func (*RepeatReq) GetDelayMs

func (m *RepeatReq) GetDelayMs() int64

func (*RepeatReq) GetErrAfter

func (m *RepeatReq) GetErrAfter() int32

func (*RepeatReq) GetMessage

func (m *RepeatReq) GetMessage() string

func (*RepeatReq) GetNumRepeats

func (m *RepeatReq) GetNumRepeats() int32

func (*RepeatReq) ProtoMessage

func (*RepeatReq) ProtoMessage()

func (*RepeatReq) Reset

func (m *RepeatReq) Reset()

func (*RepeatReq) String

func (m *RepeatReq) String() string

type RepeatResp

type RepeatResp struct {
	// Repeated is how many times the message has already been repeated
	// (i.e. on first resp Repeated is 0, last of n is n - 1)
	ID int32 `protobuf:"varint,3,opt,name=ID" json:"ID,omitempty"`
	// The same message as from the request
	Message string `protobuf:"bytes,1,opt,name=Message" json:"Message,omitempty"`
	// DelayedMs is how many milliseconds the delay actually took
	DelayedMs int64 `protobuf:"varint,2,opt,name=DelayedMs" json:"DelayedMs,omitempty"`
}

func (*RepeatResp) Descriptor

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

func (*RepeatResp) GetDelayedMs

func (m *RepeatResp) GetDelayedMs() int64

func (*RepeatResp) GetID

func (m *RepeatResp) GetID() int32

func (*RepeatResp) GetMessage

func (m *RepeatResp) GetMessage() string

func (*RepeatResp) ProtoMessage

func (*RepeatResp) ProtoMessage()

func (*RepeatResp) Reset

func (m *RepeatResp) Reset()

func (*RepeatResp) String

func (m *RepeatResp) String() string

type RepeatRespOrError

type RepeatRespOrError struct {
	Msg *RepeatResp
	Err error
}

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
	// github.com/golang/protobuf/protoc-gen-go/descriptor.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
}

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 NewTwirperServer

func NewTwirperServer(svc Twirper, hooks *twirp.ServerHooks) TwirpServer

type Twirper

type Twirper interface {
	// Echo sends back what it received
	Echo(ctx context.Context, in *EchoReq) (*EchoReq, error)

	// Repeat returns a stream of repeated messages
	Repeat(ctx context.Context, in *RepeatReq) (<-chan RepeatRespOrError, error)
}

A Twirper repeats stuff

func NewTwirperJSONClient

func NewTwirperJSONClient(addr string, client HTTPClient) Twirper

NewTwirperJSONClient creates a JSON client that implements the Twirper interface. It communicates using JSON and can be configured with a custom HTTPClient.

func NewTwirperProtobufClient

func NewTwirperProtobufClient(addr string, client HTTPClient) Twirper

NewTwirperProtobufClient creates a Protobuf client that implements the Twirper interface. It communicates using Protobuf and can be configured with a custom HTTPClient.

Jump to

Keyboard shortcuts

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