Documentation ¶
Index ¶
- func BadRouteError(msg string, method, url string) *xerrors.APIError
- func Register(fn RegisterFunc)
- func ServeJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request, hooks Hooks, ...)
- func ServerHTTPStatusFromErrorCode(code xerrors.Code) int
- func WriteError(ctx context.Context, resp http.ResponseWriter, hooks Hooks, info HookInfo, ...)
- type ErrorInterface
- type ExecFunc
- type HookInfo
- type Hooks
- type HooksBuilder
- type HooksFunc
- type Message
- type Muxer
- type RegisterFunc
- type Registry
- type ServeFunc
- type Server
- func MustNewServer(builder interface{}, hooks ...HooksBuilder) Server
- func MustNewServers(builders ...interface{}) (servers []Server)
- func NewServer(builder interface{}, hooks ...HooksBuilder) (Server, error)
- func NewServers(builders ...interface{}) (servers []Server, _ error)
- func StripPrefix(prefix string, servers ...Server) Server
- func WithHooks(servers []Server, hooks ...HooksBuilder) []Server
- func WithPrefix(prefix string, servers []Server) []Server
- type TwError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(fn RegisterFunc)
func WriteError ¶
Types ¶
type ErrorInterface ¶
type ErrorInterface interface { // Code is of the valid error codes. Code() xerrors.Code // Msg returns a human-readable, unstructured messages describing the error. Msg() string // WithMeta returns a copy of the Error with the given key-value pair attached // as metadata. If the key is already set, it is overwritten. WithMeta(key string, val string) ErrorInterface // Meta returns the stored value for the given key. If the key has no set // value, Meta returns an empty string. There is no way to distinguish between // an unset value and an explicit empty string. Meta(key string) string // MetaMap returns the complete key-value metadata map stored on the error. MetaMap() map[string]string // Error returns a string of the form "twirp error <Type>: <Msg>" Error() string }
type Hooks ¶
type Hooks struct { RequestReceived func(ctx context.Context, info HookInfo) (context.Context, error) RequestRouted func(ctx context.Context, info HookInfo) (context.Context, error) ResponsePrepared func(ctx context.Context, info HookInfo, respHeaders http.Header) (context.Context, error) ResponseSent func(ctx context.Context, info HookInfo) Error func(ctx context.Context, info HookInfo, err error) (context.Context, error) }
func WrapHooks ¶
func WrapHooks(builder HooksBuilder) (res Hooks)
type HooksBuilder ¶
type HooksBuilder interface {
BuildHooks() Hooks
}
func ChainHooks ¶
func ChainHooks(hooks ...HooksBuilder) HooksBuilder
type RegisterFunc ¶
type RegisterFunc func(builder interface{}, hooks ...HooksBuilder) (Server, bool)
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) NewServer ¶
func (r *Registry) NewServer(builder interface{}, hooks ...HooksBuilder) (Server, error)
func (*Registry) NewServers ¶
func (*Registry) Register ¶
func (r *Registry) Register(fn RegisterFunc)
type ServeFunc ¶
type Server ¶
type Server interface { http.Handler PathPrefix() string // WithHooks returns a new server which calls given hooks on processing http // requests. It must always clone the server and leave the original one // unaffected. WithHooks(HooksBuilder) Server }
func MustNewServer ¶
func MustNewServer(builder interface{}, hooks ...HooksBuilder) Server
func MustNewServers ¶
func MustNewServers(builders ...interface{}) (servers []Server)
func NewServer ¶
func NewServer(builder interface{}, hooks ...HooksBuilder) (Server, error)
func NewServers ¶
func StripPrefix ¶
func WithHooks ¶
func WithHooks(servers []Server, hooks ...HooksBuilder) []Server
func WithPrefix ¶
type TwError ¶
type TwError interface { ErrorInterface Cause() error OrigFile() string OrigLine() int }
func TwirpError ¶
Click to show internal directories.
Click to hide internal directories.