router

package
v0.0.0-...-86283f3 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONMarshal

func JSONMarshal(t interface{}) ([]byte, error)

JSONMarshal does not escape HTML

func MarshalJSONErr

func MarshalJSONErr(message, code string, args ...any) []byte

func SendError

func SendError(w http.ResponseWriter, message, code string, statusCode int)

func SendErrorAndLog

func SendErrorAndLog(w http.ResponseWriter, message, code string, statusCode int, origin string, err error)

func SendInternalError

func SendInternalError(w http.ResponseWriter, origin string, err error)

func SendSuccess

func SendSuccess(w http.ResponseWriter, resp interface{})

Types

type JSONErr

type JSONErr struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
	Code    string `json:"code,omitempty"`
}

func UnmarshalJSONErr

func UnmarshalJSONErr(b []byte) *JSONErr

type Router

type Router struct {
	State any
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(config *RouterConfig) (*Router, error)

func (*Router) ServeHTTP

func (s *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RouterConfig

type RouterConfig struct {
	// any struct or map you may need
	State any

	// folder path
	ServeHTMLFolder       string
	HTMLFolderDomainNames []string

	PageViewsPath string

	RedirectHTTP2HTTPS bool
	OnlyHTTPS          bool

	PerDomainHijack map[string][]func(r *Router, spath []string, w http.ResponseWriter, req *http.Request, domain string) bool

	AllowCustomHeaders []string

	AllowOrigins []string

	// If set to true, we ignore files that are not user+group+world readable on the local filesystem,
	// so even if you accidentally copy a sensitive file into the web root, it's unlikely to be served.
	IgnoreNotWorldReadable bool
}

Jump to

Keyboard shortcuts

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