thttp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindFromTags

func BindFromTags(v any, r *http.Request) error

BindFromTags extracts parameters from path, query, header, cookie, and form struct tags.

func HTTP

func HTTP[Req, Res any](act *action.BuiltAction[Req, Res], options ...AdapterOption) http.Handler

func ReadFormFile

func ReadFormFile(r *http.Request, fieldName string, maxBytes int64) ([]byte, string, error)

ReadFormFile extracts and reads a file from a multipart form request.

func StreamIterator

func StreamIterator[T any](ctx context.Context, w http.ResponseWriter, seq iter.Seq2[T, error], c codec.Codec) error

StreamIterator writes an iter.Seq2 stream directly to the response socket.

func StreamNDJSON

func StreamNDJSON[E any](c codec.Codec, getIter func(ctx context.Context) (iter.Seq2[E, error], error)) http.HandlerFunc

StreamNDJSON writes an iterator directly to http.ResponseWriter as NDJSON with O(1) memory.

Types

type AdapterConfig

type AdapterConfig struct {
	MaxBodyBytes        int64
	GenerateExecutionID bool
	Methods             []string
}

type AdapterOption

type AdapterOption func(*AdapterConfig)

func WithMaxBodyBytes

func WithMaxBodyBytes(n int64) AdapterOption

func WithMethods

func WithMethods(methods ...string) AdapterOption

type FormFile

type FormFile struct {
	Filename    string
	ContentType string
	Bytes       []byte
}

FormFile provides multipart/form-data upload decoding.

func (*FormFile) ReadField

func (f *FormFile) ReadField(r *http.Request, fieldName string, maxBytes int64) error

type HTTPDecoder

type HTTPDecoder interface {
	FromHTTPRequest(r *http.Request) error
}

type HTTPRoute

type HTTPRoute struct {
	Method string
	Path   string
}

func DELETE

func DELETE(path string) HTTPRoute

func GET

func GET(path string) HTTPRoute
func HEAD(path string) HTTPRoute

func InferRoute

func InferRoute(reqType reflect.Type) HTTPRoute

InferRoute analyzes a Request struct type and generates standard RESTful routes at boot time.

func PATCH

func PATCH(path string) HTTPRoute

func POST

func POST(path string) HTTPRoute

func PUT

func PUT(path string) HTTPRoute

func (HTTPRoute) String

func (r HTTPRoute) String() string

type InMemoryBroadcaster

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

func NewBroadcaster

func NewBroadcaster(buffer int) *InMemoryBroadcaster

func (*InMemoryBroadcaster) Publish

func (b *InMemoryBroadcaster) Publish(channel string, payload []byte) (delivered int, dropped int)

func (*InMemoryBroadcaster) Subscribe

func (b *InMemoryBroadcaster) Subscribe(channel string) (<-chan []byte, func())

type ListParams

type ListParams struct {
	Search string `json:"search" query:"search"`
	Limit  int    `json:"limit" query:"limit"`
	Page   int    `json:"page" query:"page"`
	Sort   string `json:"sort" query:"sort"`
}

ListParams is a standardized URL pagination and filter decoder.

func (*ListParams) FromHTTPRequest

func (l *ListParams) FromHTTPRequest(r *http.Request) error

type Option

type Option func(*Transport)

func WithBroadcaster

func WithBroadcaster(b StreamBroadcaster) Option

func WithCodec

func WithCodec(c codec.Codec) Option

func WithIdempotencyStore

func WithIdempotencyStore(store action.IdempotencyStore) Option

func WithReadTimeout

func WithReadTimeout(d time.Duration) Option

func WithWriteTimeout

func WithWriteTimeout(d time.Duration) Option

type PathID

type PathID[T comparable] struct {
	ID T `json:"id"`
}

PathID is a zero-allocation generic path parameter decoder for /{id}.

func (*PathID[T]) FromHTTPRequest

func (p *PathID[T]) FromHTTPRequest(r *http.Request) error

func (*PathID[T]) GetID

func (p *PathID[T]) GetID() T

type Query

type Query[T any] struct {
	Data T
}

Query[T] fills any struct T from URL query parameters automatically.

func (*Query[T]) FromHTTPRequest

func (q *Query[T]) FromHTTPRequest(r *http.Request) error

type RawHTTPHandler

type RawHTTPHandler struct {
	Method  string
	Path    string
	Handler http.HandlerFunc
}

func RawHandler

func RawHandler(method, path string, h http.HandlerFunc) RawHTTPHandler

func (RawHTTPHandler) String

func (r RawHTTPHandler) String() string

type SSERoute

type SSERoute struct {
	Path        string
	Channel     string
	Broadcaster StreamBroadcaster
}

func Stream

func Stream(path string) SSERoute

func (SSERoute) String

func (r SSERoute) String() string

func (SSERoute) WithBroadcaster

func (r SSERoute) WithBroadcaster(b StreamBroadcaster) SSERoute

func (SSERoute) WithChannel

func (r SSERoute) WithChannel(ch string) SSERoute

type StreamBroadcaster

type StreamBroadcaster interface {
	Subscribe(channel string) (<-chan []byte, func())
	Publish(channel string, payload []byte) (delivered int, dropped int)
}

type Transport

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

func New

func New(addr string, opts ...Option) *Transport

func (*Transport) CanHandle

func (t *Transport) CanHandle(b action.Binding) bool

func (*Transport) Do

func (t *Transport) Do(ctx context.Context, _ any) (any, error)

func (*Transport) Handler

func (t *Transport) Handler() http.Handler

func (*Transport) Mount

func (t *Transport) Mount(actions []action.AnyAction)

func (*Transport) Mux

func (t *Transport) Mux() *http.ServeMux

func (*Transport) String

func (t *Transport) String() string

func (*Transport) Use

func (t *Transport) Use(mw ...func(http.Handler) http.Handler) *Transport

Jump to

Keyboard shortcuts

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