Documentation ¶
Overview ¶
weft helps with web applications.
Index ¶
- Constants
- func AssetHandler(r *http.Request, h http.Header, b *bytes.Buffer) error
- func AssetPath(path string) string
- func CheckQuery(r *http.Request, method, required, optional []string) error
- func CheckQueryValid(r *http.Request, method, required, optional []string, f QueryValidator) (url.Values, error)
- func CreateSubResourceTag(path string) (template.HTML, error)
- func DataDog(apiKey, hostName, appName string, logger Logger)
- func HTMLError(e error, h http.Header, b *bytes.Buffer) error
- func MakeDirectHandler(rh DirectRequestHandler, eh ErrorHandler) http.HandlerFunc
- func MakeHandler(rh RequestHandler, eh ErrorHandler) http.HandlerFunc
- func NoMatch(r *http.Request, h http.Header, b *bytes.Buffer) error
- func SRIforPath(path string) string
- func SetLogger(l Logger)
- func Soh(r *http.Request, h http.Header, b *bytes.Buffer) error
- func Status(err error) int
- func TextError(e error, h http.Header, b *bytes.Buffer) error
- func Up(r *http.Request, h http.Header, b *bytes.Buffer) error
- func UseError(e error, h http.Header, b *bytes.Buffer) error
- type DirectRequestHandler
- type Error
- type ErrorHandler
- type Logger
- type QueryValidator
- type RequestHandler
- type StatusError
Constants ¶
const ( ErrNotFound = `` /* 1519-byte string literal not displayed */ ErrGone = `` /* 1281-byte string literal not displayed */ ErrBadRequest = `` /* 861-byte string literal not displayed */ ErrMethodNotAllowed = `` /* 883-byte string literal not displayed */ )
const (
GZIP = "gzip"
)
Variables ¶
This section is empty.
Functions ¶
func AssetHandler ¶
AssetHandler serves assets from the local directory `assets/assets`. Assets are loaded from this directory on start up and served from memory. Any errors during start up will be served by AssetHandlers. Assets are served at the path `/assets/...` and can be also be served with a hashed path which finger prints the asset for uniqueness for caching e.g.,
/assets/bootstrap/hello.css /assets/bootstrap/1fdd2266-hello.css
The finger printed path can be looked up with AssetPath.
func AssetPath ¶
AssetPath returns the finger printed path for path e.g., `/assets/bootstrap/hello.css` returns `/assets/bootstrap/1fdd2266-hello.css`.
func CheckQuery ¶
CheckQuery inspects r and makes sure that the method is allowed, that all required query parameters are present, and that no more than the required and optional parameters are present.
func CheckQueryValid ¶
func CheckQueryValid(r *http.Request, method, required, optional []string, f QueryValidator) (url.Values, error)
CheckQueryValid calls CheckQuery and then validates the query parameters using f. It is an error for f to be nil.
func CreateSubResourceTag ¶
Generates a tag for a resource with the hashed path and SRI hash. Returns a template.HTML so it won't throw warnings with golangci-lint
func HTMLError ¶
HTMLError writes error pages to b for non nil error. Headers are set for intermediate caches.
Implements ErrorHandler
func MakeDirectHandler ¶
func MakeDirectHandler(rh DirectRequestHandler, eh ErrorHandler) http.HandlerFunc
MakeDirectHandler executes rh. The caller should write directly to w for success (200) only. In the case of an rh returning an error ErrorHandler is executed and the response written to the client.
Responses are counted. rh is not wrapped with a timer as this includes the write to the client.
func MakeHandler ¶
func MakeHandler(rh RequestHandler, eh ErrorHandler) http.HandlerFunc
MakeHandler returns an http.Handler that executes RequestHandler and collects timing information and metrics. In the case of errors ErrorHandler is used to set error content for the client. 50x errors are logged.
func SRIforPath ¶
func SetLogger ¶
func SetLogger(l Logger)
SetLogger sets the logger used for logging. If not set log messages are discarded.
func Status ¶
Status returns the HTTP status code appropriate for err. It returns:
- http.StatusOk if err is nil
- err.Code if err is a StatusErr and Code is set
- otherwise http.StatusServiceUnavailable
func TextError ¶
TextError writes text errors to b for non nil error. Headers are set for intermediate caches.
Implements ErrorHandler
Types ¶
type DirectRequestHandler ¶
DirectRequestHandler allows writing to the http.ResponseWriter directly. Should return the number of bytes written to w and any errors.
type ErrorHandler ¶
ErrorHandler should write the error for err into b and adjust h as required. err can be nil
type Logger ¶
type Logger interface {
Printf(string, ...interface{})
}
Logger defines an interface for logging.
type QueryValidator ¶
QueryValidator returns an error for any invalid query parameter values.
type RequestHandler ¶
RequestHandler should write the response for r into b and adjust h as required.
type StatusError ¶
StatusError is for errors with HTTP status codes. If Code is http.StatusBadRequest then Err.Error() should return a message that is suitable for returning to the client. If Code is http.StatusMovedPermanently or http.StatusSeeOther then Err.Error should return the redirect URL.
func (StatusError) Error ¶
func (s StatusError) Error() string
func (StatusError) Status ¶
func (s StatusError) Status() int