Documentation ¶
Index ¶
- Constants
- Variables
- func WriteError(resp http.ResponseWriter, err error)
- type API
- type Content
- func (*Content) Descriptor() ([]byte, []int)deprecated
- func (x *Content) GetCreatedAt() string
- func (x *Content) GetData() []byte
- func (x *Content) GetMetadata() *Metadata
- func (x *Content) GetType() ContentType
- func (*Content) ProtoMessage()
- func (x *Content) ProtoReflect() protoreflect.Message
- func (x *Content) Reset()
- func (x *Content) String() string
- type ContentID
- type ContentType
- func (ContentType) Descriptor() protoreflect.EnumDescriptor
- func (x ContentType) Enum() *ContentType
- func (ContentType) EnumDescriptor() ([]byte, []int)deprecated
- func (x ContentType) Number() protoreflect.EnumNumber
- func (x ContentType) String() string
- func (ContentType) Type() protoreflect.EnumType
- type File
- type HTTPClient
- type Metadata
- type NormalizedContent
- type Query
- type Results
- type StoredContent
- func (*StoredContent) Descriptor() ([]byte, []int)deprecated
- func (x *StoredContent) GetContent() *Content
- func (x *StoredContent) GetNormalized() *NormalizedContent
- func (*StoredContent) ProtoMessage()
- func (x *StoredContent) ProtoReflect() protoreflect.Message
- func (x *StoredContent) Reset()
- func (x *StoredContent) String() string
- type TwirpServer
Constants ¶
const APIPathPrefix = "/twirp/lunabrain.API/"
APIPathPrefix 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 ( ContentType_name = map[int32]string{ 0: "TEXT", 1: "AUDIO", 2: "URL", } ContentType_value = map[string]int32{ "TEXT": 0, "AUDIO": 1, "URL": 2, } )
Enum value maps for ContentType.
var File_api_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 API ¶
type API interface { Save(context.Context, *Content) (*ContentID, error) Search(context.Context, *Query) (*Results, error) }
func NewAPIJSONClient ¶
func NewAPIJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) API
NewAPIJSONClient creates a JSON client that implements the API interface. It communicates using JSON and can be configured with a custom HTTPClient.
func NewAPIProtobufClient ¶
func NewAPIProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) API
NewAPIProtobufClient creates a Protobuf client that implements the API interface. It communicates using Protobuf and can be configured with a custom HTTPClient.
type Content ¶
type Content struct { Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` Type ContentType `protobuf:"varint,2,opt,name=type,proto3,enum=lunabrain.ContentType" json:"type,omitempty"` Metadata *Metadata `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"` CreatedAt string `protobuf:"bytes,4,opt,name=createdAt,proto3" json:"createdAt,omitempty"` // contains filtered or unexported fields }
Content has data and metadata
func (*Content) Descriptor
deprecated
func (*Content) GetCreatedAt ¶
func (*Content) GetMetadata ¶
func (*Content) GetType ¶
func (x *Content) GetType() ContentType
func (*Content) ProtoMessage ¶
func (*Content) ProtoMessage()
func (*Content) ProtoReflect ¶
func (x *Content) ProtoReflect() protoreflect.Message
type ContentID ¶
type ContentID struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // contains filtered or unexported fields }
func (*ContentID) Descriptor
deprecated
func (*ContentID) ProtoMessage ¶
func (*ContentID) ProtoMessage()
func (*ContentID) ProtoReflect ¶
func (x *ContentID) ProtoReflect() protoreflect.Message
type ContentType ¶
type ContentType int32
const ( ContentType_TEXT ContentType = 0 ContentType_AUDIO ContentType = 1 ContentType_URL ContentType = 2 )
func (ContentType) Descriptor ¶
func (ContentType) Descriptor() protoreflect.EnumDescriptor
func (ContentType) Enum ¶
func (x ContentType) Enum() *ContentType
func (ContentType) EnumDescriptor
deprecated
func (ContentType) EnumDescriptor() ([]byte, []int)
Deprecated: Use ContentType.Descriptor instead.
func (ContentType) Number ¶
func (x ContentType) Number() protoreflect.EnumNumber
func (ContentType) String ¶
func (x ContentType) String() string
func (ContentType) Type ¶
func (ContentType) Type() protoreflect.EnumType
type File ¶
type File struct { Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` // contains filtered or unexported fields }
func (*File) Descriptor
deprecated
func (*File) ProtoMessage ¶
func (*File) ProtoMessage()
func (*File) ProtoReflect ¶
func (x *File) ProtoReflect() protoreflect.Message
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 Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
func (*Metadata) Descriptor
deprecated
func (*Metadata) ProtoMessage ¶
func (*Metadata) ProtoMessage()
func (*Metadata) ProtoReflect ¶
func (x *Metadata) ProtoReflect() protoreflect.Message
type NormalizedContent ¶
type NormalizedContent struct { Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` // contains filtered or unexported fields }
func (*NormalizedContent) Descriptor
deprecated
func (*NormalizedContent) Descriptor() ([]byte, []int)
Deprecated: Use NormalizedContent.ProtoReflect.Descriptor instead.
func (*NormalizedContent) GetData ¶
func (x *NormalizedContent) GetData() string
func (*NormalizedContent) ProtoMessage ¶
func (*NormalizedContent) ProtoMessage()
func (*NormalizedContent) ProtoReflect ¶
func (x *NormalizedContent) ProtoReflect() protoreflect.Message
func (*NormalizedContent) Reset ¶
func (x *NormalizedContent) Reset()
func (*NormalizedContent) String ¶
func (x *NormalizedContent) String() string
type Query ¶
type Query struct { Query string `protobuf:"bytes,1,opt,name=query,proto3" json:"query,omitempty"` // contains filtered or unexported fields }
func (*Query) Descriptor
deprecated
func (*Query) ProtoMessage ¶
func (*Query) ProtoMessage()
func (*Query) ProtoReflect ¶
func (x *Query) ProtoReflect() protoreflect.Message
type Results ¶
type Results struct { StoredContent []*StoredContent `protobuf:"bytes,1,rep,name=storedContent,proto3" json:"storedContent,omitempty"` // contains filtered or unexported fields }
func (*Results) Descriptor
deprecated
func (*Results) GetStoredContent ¶
func (x *Results) GetStoredContent() []*StoredContent
func (*Results) ProtoMessage ¶
func (*Results) ProtoMessage()
func (*Results) ProtoReflect ¶
func (x *Results) ProtoReflect() protoreflect.Message
type StoredContent ¶
type StoredContent struct { Content *Content `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"` Normalized *NormalizedContent `protobuf:"bytes,2,opt,name=normalized,proto3" json:"normalized,omitempty"` // contains filtered or unexported fields }
func (*StoredContent) Descriptor
deprecated
func (*StoredContent) Descriptor() ([]byte, []int)
Deprecated: Use StoredContent.ProtoReflect.Descriptor instead.
func (*StoredContent) GetContent ¶
func (x *StoredContent) GetContent() *Content
func (*StoredContent) GetNormalized ¶
func (x *StoredContent) GetNormalized() *NormalizedContent
func (*StoredContent) ProtoMessage ¶
func (*StoredContent) ProtoMessage()
func (*StoredContent) ProtoReflect ¶
func (x *StoredContent) ProtoReflect() protoreflect.Message
func (*StoredContent) Reset ¶
func (x *StoredContent) Reset()
func (*StoredContent) String ¶
func (x *StoredContent) String() string
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 NewAPIServer ¶
func NewAPIServer(svc API, opts ...interface{}) TwirpServer
NewAPIServer 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).