serve

package module
v0.0.0-...-6deb74b Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultReadTimeout  = time.Second * 30
	DefaultWriteTimeout = time.Second * 60
	DefaultIdleTimeout  = time.Second * 120
	DefaultAddr         = ":http"
	DefaultTLSAddr      = ":https"
)
View Source
const DefaultIndexFile = "index.html"

Variables

View Source
var ErrContentLengthMismatch = errors.New("content-length mismatch")

Functions

func App

func App(opt ...AppOption) func(http.ResponseWriter, *http.Request, fs.FS, ...Option) (*Info, error)

func AutoCert

func AutoCert(email string, host string) *tls.Config

func Error

func Error(w http.ResponseWriter, err error)

func ErrorStatusCode

func ErrorStatusCode(err error) int

func Handle

func Handle(w http.ResponseWriter, r *http.Request, fn func() (*Info, error))

func Listen

func Listen(h http.Handler, opt ...ListenOption)

func NewAppHandler

func NewAppHandler(fsys fs.FS, opt ...AppOption) http.Handler

Types

type AppOption

type AppOption func(*appConfig)

func Index

func Index(name string) AppOption

type Info

type Info struct {
	StatusCode    int
	ContentLength int64
	ContentType   string
	Location      string
	LastModified  time.Time
	MaxAge        time.Duration
	Immutable     bool
	Compress      bool
	Disposition   string
	Range         *[2]int64
}

func Blob

func Blob(w http.ResponseWriter, r *http.Request, b blob.Blob, opt ...Option) (*Info, error)
func Header(w http.ResponseWriter, opt ...Option) (*Info, error)

func JSON

func JSON(w http.ResponseWriter, r *http.Request, v any, opt ...Option) (*Info, error)

func Reader

func Reader(rw http.ResponseWriter, r *http.Request, rd io.Reader, opt ...Option) (*Info, error)

type ListenOption

type ListenOption func(*listenConfig)

func Addr

func Addr(addr string) ListenOption

func TLS

func TLS(c *tls.Config) ListenOption

type Option

type Option func(c *config)

func Attachment

func Attachment(name string) Option

func Compress

func Compress(b bool) Option

func ContentLength

func ContentLength(n int64) Option

func ContentType

func ContentType(ct string) Option

func ContentTypeFromPath

func ContentTypeFromPath(p string) Option

func Immutable

func Immutable(b bool) Option

func LastModified

func LastModified(t time.Time) Option

func Location

func Location(loc string) Option

func MaxAge

func MaxAge(d time.Duration) Option

func NoOp

func NoOp() Option

func Range

func Range(start, end int64) Option

func StatusCode

func StatusCode(n int) Option

type StatusCoder

type StatusCoder interface {
	StatusCode() int
}

Jump to

Keyboard shortcuts

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