fmhttp

package
v0.0.0-...-5a8ed98 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyContext

type AnyContext any

type AnyHandler

type AnyHandler any

type ChainExecutor

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

func (*ChainExecutor) Next

func (ce *ChainExecutor) Next() Response

type Context

type Context struct {
	Request *http.Request

	WrappedContext AnyContext

	HttpServer     *HttpServer
	ResponseWriter *ResponseWriterWrapper

	HandlerData map[string]any
	// contains filtered or unexported fields
}

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) FormParam

func (c *Context) FormParam(key string, defs ...string) string

func (*Context) FormParamInt64

func (c *Context) FormParamInt64(key string, defs ...int64) int64

func (*Context) IsMethodGet

func (c *Context) IsMethodGet() bool

func (*Context) IsMethodPost

func (c *Context) IsMethodPost() bool

func (*Context) IsResponseWritten

func (c *Context) IsResponseWritten() bool

func (*Context) PathParam

func (c *Context) PathParam(key string, defs ...string) string

func (*Context) PathParamInt64

func (c *Context) PathParamInt64(key string, defs ...int64) int64

func (*Context) PostParam

func (c *Context) PostParam(key string, defs ...string) string

func (*Context) PostParamInt64

func (c *Context) PostParamInt64(key string, defs ...int64) int64

func (*Context) QueryParam

func (c *Context) QueryParam(key string, defs ...string) string

func (*Context) QueryParamInt64

func (c *Context) QueryParamInt64(key string, defs ...int64) int64

func (*Context) RealRemoteIp

func (c *Context) RealRemoteIp() string

func (*Context) RequestJson

func (c *Context) RequestJson() *fmutil.JsonValue

func (*Context) RequestJsonUnmarshal

func (c *Context) RequestJsonUnmarshal(v any) error

func (*Context) Respond

func (c *Context) Respond(vars ...any) *ResponseCommon

func (*Context) RespondFile

func (c *Context) RespondFile(name string, file fs.File) *ResponseCommon

func (*Context) RespondJson

func (c *Context) RespondJson(v any) *ResponseCommon

func (*Context) RespondPathTmpl

func (c *Context) RespondPathTmpl(data map[string]any) *ResponseCommon

func (*Context) RespondRedirectSameSite

func (c *Context) RespondRedirectSameSite(location string, params ...fmutil.Map) *ResponseCommon

func (*Context) RespondTmpl

func (c *Context) RespondTmpl(name string, data map[string]any) *ResponseCommon

func (*Context) Session

func (c *Context) Session() *Session

func (*Context) UriHost

func (c *Context) UriHost() string

func (*Context) Value

func (c *Context) Value(key any) any

type HandlerCaller

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

func NewHandlerCaller

func NewHandlerCaller(p AnyHandler) *HandlerCaller

func (*HandlerCaller) Call

func (hc *HandlerCaller) Call(ce *ChainExecutor, isMiddleware bool) Response

type HttpServer

type HttpServer struct {
	AssetsDir     fs.FS
	AssetsWebRoot fs.FS

	WrapContext func(r *Context) AnyContext
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(opt *Options) *HttpServer

func (*HttpServer) HandleAssets

func (hs *HttpServer) HandleAssets(pattern string)

func (*HttpServer) HandleRequest

func (hs *HttpServer) HandleRequest(pattern string, handlers ...AnyHandler)

func (*HttpServer) ListenAndServe

func (hs *HttpServer) ListenAndServe() error

func (*HttpServer) ServeAssetFile

func (hs *HttpServer) ServeAssetFile(c *Context) Response

func (*HttpServer) TmplRender

func (hs *HttpServer) TmplRender(w io.Writer, name string, data map[string]any) error

func (*HttpServer) UseMiddleware

func (hs *HttpServer) UseMiddleware(handlers ...AnyHandler)

type Options

type Options struct {
	DevMode  bool
	Listen   string
	AssetsFS fs.FS

	SessionDir             string
	SessionCookieSecureKey string
	SessionCookieName      string
	SessionCookieOptions   *sessions.Options

	RealIpHeader        string
	TrustHttpHeaderFrom []string
}

type PatternDelegator

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

func (*PatternDelegator) Delete

func (pd *PatternDelegator) Delete(h ...AnyHandler) *PatternDelegator

func (*PatternDelegator) Get

func (*PatternDelegator) Head

func (*PatternDelegator) Options

func (pd *PatternDelegator) Options(h ...AnyHandler) *PatternDelegator

func (*PatternDelegator) Patch

func (pd *PatternDelegator) Patch(h ...AnyHandler) *PatternDelegator

func (*PatternDelegator) Post

func (*PatternDelegator) Put

type RedirectPermanent

type RedirectPermanent string

type RedirectSeeOther

type RedirectSeeOther string

type RedirectTemporary

type RedirectTemporary string

type RequestHandler

type RequestHandler interface {
	Handle(c *Context) Response
}

type RequestHandlerFunc

type RequestHandlerFunc func(*Context) Response

type Response

type Response interface {
	StatusCode() int
	Header() http.Header
	RespondTo(w http.ResponseWriter) (int64, error)
}

type ResponseCommon

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

func (*ResponseCommon) Header

func (wr *ResponseCommon) Header() http.Header

func (*ResponseCommon) RespondTo

func (wr *ResponseCommon) RespondTo(w http.ResponseWriter) (int64, error)

func (*ResponseCommon) SetStatusCode

func (wr *ResponseCommon) SetStatusCode(v int) *ResponseCommon

func (*ResponseCommon) StatusCode

func (wr *ResponseCommon) StatusCode() int

type ResponseWriterWrapper

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

func (*ResponseWriterWrapper) Header

func (w *ResponseWriterWrapper) Header() http.Header

func (*ResponseWriterWrapper) Write

func (w *ResponseWriterWrapper) Write(bytes []byte) (int, error)

func (*ResponseWriterWrapper) WriteHeader

func (w *ResponseWriterWrapper) WriteHeader(statusCode int)

type Router

type Router interface {
	RequestHandler

	// Use appends one or more middlewares onto the Router stack.
	Use(middlewares ...AnyHandler)

	With(h ...AnyHandler) *WithDelegator

	// Group adds a new inline-Router along the current routing path, with a fresh middleware stack for the inline-Router.
	Group(fn func(r Router)) Router

	// Route mounts a sub-Router along a `pattern“ string.
	Route(pattern string, fn func(r Router)) Router

	Any(pattern string, h ...AnyHandler)
	Method(method, pattern string, h ...AnyHandler)

	Connect(pattern string, h ...AnyHandler)
	Delete(pattern string, h ...AnyHandler)
	Get(pattern string, h ...AnyHandler)
	Head(pattern string, h ...AnyHandler)
	Options(pattern string, h ...AnyHandler)
	Patch(pattern string, h ...AnyHandler)
	Post(pattern string, h ...AnyHandler)
	Put(pattern string, h ...AnyHandler)
	Trace(pattern string, h ...AnyHandler)

	Pattern(pattern string, h ...AnyHandler) *PatternDelegator

	// NotFound defines a handler to respond whenever a route could not be found.
	NotFound(h ...AnyHandler)

	// MethodNotAllowed defines a handler to respond whenever a method is not allowed.
	MethodNotAllowed(h ...AnyHandler)
}

func NewRouter

func NewRouter() Router

type Session

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

func NewSession

func NewSession(session *sessions.Session) *Session

func (*Session) AutoSave

func (ws *Session) AutoSave(w http.ResponseWriter, r *http.Request) error

func (*Session) Destroy

func (ws *Session) Destroy()

func (*Session) Get

func (ws *Session) Get(key string) any

func (*Session) GetInt64

func (ws *Session) GetInt64(key string) int64

func (*Session) GetString

func (ws *Session) GetString(key string) string

func (*Session) Remove

func (ws *Session) Remove(key string)

func (*Session) Set

func (ws *Session) Set(key string, val any)

func (*Session) SetChanged

func (ws *Session) SetChanged()

type TemplateRender

type TemplateRender struct {
	DevMode    bool
	TemplateFS fs.FS
	// contains filtered or unexported fields
}

func NewTemplateRender

func NewTemplateRender(templateFS fs.FS) *TemplateRender

func (*TemplateRender) Render

func (r *TemplateRender) Render(wr io.Writer, tmplName string, data map[string]any) error

type WithDelegator

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

func (WithDelegator) Group

func (w WithDelegator) Group(fn func(r Router)) Router

Jump to

Keyboard shortcuts

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