endpoint

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 5 Imported by: 0

README

Endpoint

Look. I set a goal for myself to minimize the number of libraries I import when creating polyform

It's generic, for better or for worst.

This works. It's "fine". But there are way better libraries to use. Probably shouldn't use this package for your personal projects.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryRequestReader

type BinaryRequestReader struct{}

func (BinaryRequestReader) Interpret

func (jrbi BinaryRequestReader) Interpret(r *http.Request) ([]byte, error)

type BinaryResponseWriter

type BinaryResponseWriter struct{}

func (BinaryResponseWriter) ContentType

func (jrw BinaryResponseWriter) ContentType(r *http.Request) ContentType

func (BinaryResponseWriter) Serialize

func (jrw BinaryResponseWriter) Serialize(w http.ResponseWriter, response []byte) (err error)

type BodyMethod

type BodyMethod[Body any] struct {
	Request RequestReader[Body]
	Handler func(request Request[Body]) error
}

func JsonBodyMethod added in v0.31.0

func JsonBodyMethod[Body any](handler func(request Request[Body]) error) BodyMethod[Body]

func (BodyMethod[Body]) ContentType

func (jse BodyMethod[Body]) ContentType(r *http.Request) ContentType

func (BodyMethod[Body]) Handle

func (jse BodyMethod[Body]) Handle(w http.ResponseWriter, r *http.Request)

type BodyResponseMethod

type BodyResponseMethod[Body any, Response any] struct {
	Request        RequestReader[Body]
	ResponseWriter ResponseWriter[Response]
	Handler        func(request Request[Body]) (Response, error)
}

func JsonMethod

func JsonMethod[Body any, Response any](handler func(request Request[Body]) (Response, error)) BodyResponseMethod[Body, Response]

func (BodyResponseMethod[Body, Response]) ContentType

func (jse BodyResponseMethod[Body, Response]) ContentType(r *http.Request) ContentType

func (BodyResponseMethod[Body, Response]) Handle

func (jse BodyResponseMethod[Body, Response]) Handle(w http.ResponseWriter, r *http.Request)

type ContentType

type ContentType string
const (
	BinaryContentType    ContentType = "application/octet-stream"
	JsonContentType      ContentType = "application/json"
	PlainTextContentType ContentType = "text/plain"
)

type Func added in v0.21.0

type Func func(r *http.Request) error

func (Func) ContentType added in v0.21.0

func (jse Func) ContentType(r *http.Request) ContentType

func (Func) Handle added in v0.21.0

func (jse Func) Handle(w http.ResponseWriter, r *http.Request)

type Handler

type Handler struct {
	Methods map[string]Method
}

func (Handler) ServeHTTP

func (se Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type JsonRequestReader

type JsonRequestReader[T any] struct{}

func (JsonRequestReader[T]) Interpret

func (jrbi JsonRequestReader[T]) Interpret(r *http.Request) (T, error)

type JsonResponseWriter

type JsonResponseWriter[Response any] struct{}

func (JsonResponseWriter[Response]) ContentType

func (jrw JsonResponseWriter[Response]) ContentType(r *http.Request) ContentType

func (JsonResponseWriter[Response]) Serialize

func (jrw JsonResponseWriter[Response]) Serialize(w http.ResponseWriter, response Response) (err error)

type Method

type Method interface {
	ContentType(r *http.Request) ContentType
	Handle(w http.ResponseWriter, r *http.Request)
}

type Request

type Request[Body any] struct {
	Body Body
	Url  string
}

type RequestReader

type RequestReader[T any] interface {
	Interpret(r *http.Request) (T, error)
}

type RequestReaderFunc added in v0.32.0

type RequestReaderFunc[T any] func(r *http.Request) (T, error)

func (RequestReaderFunc[T]) Interpret added in v0.32.0

func (f RequestReaderFunc[T]) Interpret(r *http.Request) (T, error)

type ResponseMethod

type ResponseMethod[Response any] struct {
	ResponseWriter ResponseWriter[Response]
	Handler        func(r *http.Request) (Response, error)
}

func JsonResponseMethod added in v0.31.0

func JsonResponseMethod[Response any](handler func(r *http.Request) (Response, error)) ResponseMethod[Response]

func (ResponseMethod[Response]) ContentType

func (jse ResponseMethod[Response]) ContentType(r *http.Request) ContentType

func (ResponseMethod[Response]) Handle

func (jse ResponseMethod[Response]) Handle(w http.ResponseWriter, r *http.Request)

type ResponseMethodContentTypeOverride added in v0.33.0

type ResponseMethodContentTypeOverride[Response any] struct {
	ResponseWriter ResponseWriter[Response]
	Content        func(r *http.Request) ContentType
	Handler        func(r *http.Request) (Response, error)
}

func (ResponseMethodContentTypeOverride[Response]) ContentType added in v0.33.0

func (jse ResponseMethodContentTypeOverride[Response]) ContentType(r *http.Request) ContentType

func (ResponseMethodContentTypeOverride[Response]) Handle added in v0.33.0

type ResponseWriter

type ResponseWriter[Response any] interface {
	Serialize(w http.ResponseWriter, response Response) (err error)
	ContentType(r *http.Request) ContentType
}

type StaticResponse added in v0.32.0

type StaticResponse struct {
	Response []byte
	Type     string
}

func StaticJson added in v0.32.0

func StaticJson(data any) (StaticResponse, error)

func (StaticResponse) ContentType added in v0.32.0

func (srw StaticResponse) ContentType(r *http.Request) ContentType

func (StaticResponse) Handle added in v0.32.0

func (srw StaticResponse) Handle(w http.ResponseWriter, r *http.Request)

type TextRequestReader added in v0.21.0

type TextRequestReader struct{}

func (TextRequestReader) Interpret added in v0.21.0

func (jrbi TextRequestReader) Interpret(r *http.Request) (string, error)

type TextResponseWriter added in v0.21.0

type TextResponseWriter struct{}

func (TextResponseWriter) ContentType added in v0.21.0

func (jrw TextResponseWriter) ContentType(r *http.Request) ContentType

func (TextResponseWriter) Serialize added in v0.21.0

func (jrw TextResponseWriter) Serialize(w http.ResponseWriter, response string) (err error)

Jump to

Keyboard shortcuts

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