httpserver

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderRequestID    = "X-Request-ID"
	DefaultMaxJSONBody = int64(1 << 20)
)

Variables

This section is empty.

Functions

func BindJSON

func BindJSON[T any](w http.ResponseWriter, r *http.Request) (T, bool)

func HandleJSON

func HandleJSON[TReq any, TResp any](fn func(context.Context, TReq) (TResp, error)) http.HandlerFunc

func JSON

func JSON(w http.ResponseWriter, status int, value any)

func NewServer

func NewServer(addr string, handler http.Handler, opts ...Option) *http.Server

func ReadBody

func ReadBody(w http.ResponseWriter, r *http.Request) ([]byte, bool)

func RequestID

func RequestID(ctx context.Context) string

Types

type Config

type Config struct {
	MaxBodyBytes      int64
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
}

type Engine

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

func NewEngine

func NewEngine(opts ...Option) *Engine

func (*Engine) Get

func (e *Engine) Get(path string, handler http.HandlerFunc)

func (*Engine) Group

func (e *Engine) Group(prefix string) *Group

func (*Engine) Handler

func (e *Engine) Handler() http.Handler

func (*Engine) Post

func (e *Engine) Post(path string, handler http.HandlerFunc)

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Engine) Use

func (e *Engine) Use(middlewares ...func(http.Handler) http.Handler)

type Group

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

func (*Group) Get

func (g *Group) Get(path string, handler http.HandlerFunc)

func (*Group) Post

func (g *Group) Post(path string, handler http.HandlerFunc)

func (*Group) Use

func (g *Group) Use(middlewares ...func(http.Handler) http.Handler)

type Option

type Option func(*Config)

func WithMaxBodyBytes

func WithMaxBodyBytes(n int64) Option

func WithTimeouts

func WithTimeouts(readHeader, read, write, idle time.Duration) Option

Jump to

Keyboard shortcuts

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