router

package
v0.0.0-...-5639506 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: BSD-3-Clause Imports: 20 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 {
	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(ctx context.Context, config *RouterConfig) (*Router, error)

func (*Router) ListenAndServe

func (s *Router) ListenAndServe() 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
	DoNoRedirectToHTTPS []string // array of domain names

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

	AllowCustomHeaders []string

	AllowOrigins      []string
	AllowSSLOnDomains []string // may contain * to match any identifier between two separator points

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

	// 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

	ListenAddrs       []*RouterConfigAddr
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration

	LogLevel logging.LogLevel
}

type RouterConfigAddr

type RouterConfigAddr struct {
	Addr    string
	IsHTTPS bool
}

Jump to

Keyboard shortcuts

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