httpd

package
v0.1.54 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWriteTimeout      = 30 * time.Second
	DefaultReadTimeout       = 60 * time.Second
	DefaultReadHeaderTimeout = 5 * time.Second
	DefaultIdleTimeout       = 30 * time.Second
)
View Source
const DaemonTypeHTTPd boot.DaemonType = "httpd"

Variables

This section is empty.

Functions

func HandleREST

func HandleREST[I any, O any](pattern string, handler RESTHandler[I, O])

func RestRecoverMiddleware

func RestRecoverMiddleware(next http.Handler) http.Handler

Types

type APIHandler

type APIHandler func(http.ResponseWriter, *http.Request) any

func (APIHandler) ServeHTTP

func (ah APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Cfg

type Cfg struct {
	Addr              string        `env:"ADDR"                long:"addr"                yaml:"addr"      validate:"required" description:"http listen address"`
	WriteTimeout      time.Duration `` /* 161-byte string literal not displayed */
	ReadTimeout       time.Duration `` /* 229-byte string literal not displayed */
	ReadHeaderTimeout time.Duration `` /* 154-byte string literal not displayed */
	IdleTimeout       time.Duration `` /* 184-byte string literal not displayed */
}

func NewCfg

func NewCfg() *Cfg

type HTTPD added in v0.1.20

type HTTPD interface {
	boot.Daemon
	Handle(pattern string, handler http.Handler)
	HandleFunc(pattern string, handler http.HandlerFunc)
	RegMiddleware(mid ...MiddlewareFunc)
	Mux() *http.ServeMux
}
var (
	D HTTPD = New()
)

func New

func New() HTTPD

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

type RESTHandler

type RESTHandler[I any, O any] func(http.ResponseWriter, *http.Request, I) (O, error)

func (RESTHandler[I, O]) ServeHTTP

func (rh RESTHandler[I, O]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RawHandler

type RawHandler func(http.ResponseWriter, *http.Request) []byte

func (RawHandler) ServeHTTP

func (rh RawHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Resp

type Resp struct {
	Code RespCode `json:"code"`
	Msg  string   `json:"msg"`
	Data any      `json:"data"`
}

type RespCode

type RespCode int
const (
	RespCodeOk   RespCode = 0
	RespCodeFail RespCode = 1
)

Jump to

Keyboard shortcuts

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