api

package
v0.0.0-...-7354109 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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.

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) Descriptor() ([]byte, []int)

Deprecated: Use Content.ProtoReflect.Descriptor instead.

func (*Content) GetCreatedAt

func (x *Content) GetCreatedAt() string

func (*Content) GetData

func (x *Content) GetData() []byte

func (*Content) GetMetadata

func (x *Content) GetMetadata() *Metadata

func (*Content) GetType

func (x *Content) GetType() ContentType

func (*Content) ProtoMessage

func (*Content) ProtoMessage()

func (*Content) ProtoReflect

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

func (*Content) Reset

func (x *Content) Reset()

func (*Content) String

func (x *Content) String() string

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) Descriptor() ([]byte, []int)

Deprecated: Use ContentID.ProtoReflect.Descriptor instead.

func (*ContentID) GetId

func (x *ContentID) GetId() string

func (*ContentID) ProtoMessage

func (*ContentID) ProtoMessage()

func (*ContentID) ProtoReflect

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

func (*ContentID) Reset

func (x *ContentID) Reset()

func (*ContentID) String

func (x *ContentID) String() string

type ContentType

type ContentType int32
const (
	ContentType_TEXT  ContentType = 0
	ContentType_AUDIO ContentType = 1
	ContentType_URL   ContentType = 2
)

func (ContentType) Descriptor

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

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) Descriptor() ([]byte, []int)

Deprecated: Use File.ProtoReflect.Descriptor instead.

func (*File) GetData

func (x *File) GetData() []byte

func (*File) ProtoMessage

func (*File) ProtoMessage()

func (*File) ProtoReflect

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

func (*File) Reset

func (x *File) Reset()

func (*File) String

func (x *File) 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 Metadata

type Metadata struct {
	// contains filtered or unexported fields
}

func (*Metadata) Descriptor deprecated

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

Deprecated: Use Metadata.ProtoReflect.Descriptor instead.

func (*Metadata) ProtoMessage

func (*Metadata) ProtoMessage()

func (*Metadata) ProtoReflect

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

func (*Metadata) Reset

func (x *Metadata) Reset()

func (*Metadata) String

func (x *Metadata) String() string

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) Descriptor() ([]byte, []int)

Deprecated: Use Query.ProtoReflect.Descriptor instead.

func (*Query) GetQuery

func (x *Query) GetQuery() string

func (*Query) ProtoMessage

func (*Query) ProtoMessage()

func (*Query) ProtoReflect

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

func (*Query) Reset

func (x *Query) Reset()

func (*Query) String

func (x *Query) String() string

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) Descriptor() ([]byte, []int)

Deprecated: Use Results.ProtoReflect.Descriptor instead.

func (*Results) GetStoredContent

func (x *Results) GetStoredContent() []*StoredContent

func (*Results) ProtoMessage

func (*Results) ProtoMessage()

func (*Results) ProtoReflect

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

func (*Results) Reset

func (x *Results) Reset()

func (*Results) String

func (x *Results) String() string

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).

Jump to

Keyboard shortcuts

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