web

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addr                           string
	ReadTimeout, ReadHeaderTimeout time.Duration
	WriteTimeout, IdleTimeout      time.Duration
	ShutdownTimeout                time.Duration
	CertFile, KeyFile              string
}

type Ctx added in v0.2.0

type Ctx interface {
	context.Context

	Request() *http.Request
	Abort()
	IsAbort() bool

	Set(key string, value any)
	Get(key string) (value any, exists bool)
	GetString(key string) (s string)
	GetBool(key string) (b bool)
	GetInt(key string) (i int)
	GetInt64(key string) (i64 int64)
	GetFloat64(key string) (f64 float64)

	Param(key string) string
	ParamBool(key string) bool
	ParamInt(key string) int
	ParamInt64(key string) int64
	ParamFloat64(key string) float64

	QueryArray(key string) (values []string, ok bool)
	Query(key string) (string, bool)
	QueryString(key string) string
	QueryBool(key string) bool
	QueryInt(key string) int
	QueryInt64(key string) int64
	QueryFloat64(key string) float64

	PostFormArray(key string) (values []string, ok bool)
	PostForm(key string) (string, bool)
	PostFormString(key string) string
	PostFormBool(key string) bool
	PostFormInt(key string) int
	PostFormInt64(key string) int64
	PostFormFloat64(key string) float64
	FormFileHeader(name string) (*multipart.FileHeader, error)

	JsonBinding(d any) error

	GetHeader(key string) string
	Header(key, value string)
	Cookie(name string) (string, error)
	SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool, sameSite http.SameSite)

	Status(code int)
	ResponseWithStatus(code int, data []byte) error
	Response(data []byte) error
	Json(data any) error
	String(data string) error
}

type Handler

type Handler func(ctx Ctx)

type HandlerFunc added in v0.2.0

type HandlerFunc func(http.Handler, http.ResponseWriter, *http.Request)

type MiddlewareHandler added in v0.2.0

type MiddlewareHandler func(ctx Ctx, next func())

type Option

type Option struct {
	Config

	MaxHeaderBytes     int
	MaxMultipartMemory int64
	ConnState          func(net.Conn, http.ConnState)
	TLSConfig          *tls.Config
	TLSNextProto       map[string]func(*http.Server, *tls.Conn, http.Handler)
	ErrorLog           *log.Logger
	BaseContext        func(net.Listener) context.Context
	ConnContext        func(ctx context.Context, c net.Conn) context.Context
}

type Router added in v0.2.0

type Router interface {
	Get(path string, f Handler)
	Head(path string, f Handler)
	Post(path string, f Handler)
	Put(path string, f Handler)
	Patch(path string, f Handler)
	Delete(path string, f Handler)
	Connect(path string, f Handler)
	Options(path string, f Handler)
	Trace(path string, f Handler)
	Any(path string, f Handler)
	Use(fs ...MiddlewareHandler)
	PathPrefix(prefix string) *router
	HostPrefix(host string) *router
}

type Server

type Server struct {
	Option
	// contains filtered or unexported fields
}

func New

func New(opt Option) *Server

func (Server) Any added in v0.2.0

func (r Server) Any(path string, f Handler)

func (Server) Connect

func (r Server) Connect(path string, f Handler)

func (Server) Delete

func (r Server) Delete(path string, f Handler)

func (Server) Get

func (r Server) Get(path string, f Handler)

func (*Server) Handler added in v0.2.0

func (s *Server) Handler(hf HandlerFunc)

func (Server) Head

func (r Server) Head(path string, f Handler)

func (Server) HostPrefix

func (r Server) HostPrefix(host string) *router

func (Server) Options

func (r Server) Options(path string, f Handler)

func (Server) Patch

func (r Server) Patch(path string, f Handler)

func (Server) PathPrefix

func (r Server) PathPrefix(prefix string) *router

func (Server) Post

func (r Server) Post(path string, f Handler)

func (Server) Put

func (r Server) Put(path string, f Handler)

func (*Server) Run

func (s *Server) Run() error

func (Server) ServeHTTP added in v0.2.0

func (r Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Server) Shutdown

func (s *Server) Shutdown() error

func (Server) Trace

func (r Server) Trace(path string, f Handler)

func (Server) Use

func (r Server) Use(fs ...MiddlewareHandler)

Jump to

Keyboard shortcuts

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