Documentation
¶
Index ¶
- func IsValidURL(url_path string) bool
- func Nginx_Log_Received_Request(caller string, r *http.Request)
- func RedirectWrapper(handler http.Handler, scheme string, url_redirect_map web_types.URLRedirectMap, ...) http.Handler
- func RunRedirectHTTPToHTTPSServer(addr string, read_timeout time.Duration, write_timeout time.Duration, ...)
- func SafelyServeFile(w http.ResponseWriter, r *http.Request, ...)
- func SafelyServeFileEmbedded(w http.ResponseWriter, r *http.Request, url_prefix string, fs_prefix string, ...)
- type HandlerEnum
- type HandlerPair
- type HandlerType
- type LongestPrefixRouter
- type MuxEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidURL ¶
func RedirectWrapper ¶
func RunRedirectHTTPToHTTPSServer ¶
func RunRedirectHTTPToHTTPSServer(addr string, read_timeout time.Duration, write_timeout time.Duration, idle_timeout time.Duration, log_request bool)
Usage:
go web.RedirectToHTTPSFunc(":8080", 5 * time.Second, 5 * time.Second)
Consider HSTS if your clients are browsers. I have manually tested this function and checked that it works whether your HTTP port is 80 or 8080. It will correct redirect to the correct https address. It will strip away any ports so you can't use a custom HTTPS port.
func SafelyServeFile ¶
func SafelyServeFile(w http.ResponseWriter, r *http.Request, url_to_dir_map web_types.URLPrefixToFileSystemDirectoryMap, log_request bool)
The user supplies a map of URL prefix to file system directory paths to the server and the server will map each URL, replacing the prefix with the file system directory path from the map. As a safety precaution, the SafelyServeFile function will refuse to serve any files which does not have the correct xattr set. It will also refuse to list directories.
I realize that the amount of logging in this function is not going to serve everyone's needs So if you want more or less logging (or you want something else), then copy and modify it so that it does what you want. This function has been manually tested to verify that it handles all edge cases correctly.
func SafelyServeFileEmbedded ¶ added in v0.10.3
func SafelyServeFileEmbedded(w http.ResponseWriter, r *http.Request, url_prefix string, fs_prefix string, embedfs embed.FS, log_request bool)
Simple function for serving embedded files Example usage: If you're serving a directory called "static" as "resources", then you want to call it like this:
SafelyServeFileEmbedded(w, r, "resources/", "static/", embedfs, false)
Types ¶
type HandlerEnum ¶
type HandlerEnum int
type HandlerPair ¶
type HandlerPair struct {
// contains filtered or unexported fields
}
func (*HandlerPair) Length ¶
func (p *HandlerPair) Length() int
In Go, it is valid to call a method on a nil pointer!!!
type HandlerType ¶
type HandlerType struct {
// contains filtered or unexported fields
}
var EXACT_MATCH_HANDLER HandlerType = HandlerType{"exact match handler"}
var LONGEST_PREFIX_HANDLER HandlerType = HandlerType{"longest prefix handler"}
type LongestPrefixRouter ¶
type LongestPrefixRouter struct {
// contains filtered or unexported fields
}
func NewLongestPrefixRouter ¶
func NewLongestPrefixRouter(entries []*MuxEntry, fallback_handler http.HandlerFunc, log_every_request bool) *LongestPrefixRouter
func (*LongestPrefixRouter) ServeHTTP ¶
func (mux *LongestPrefixRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP dispatches the request to the handler whose pattern most closely matches the RequestURI.
type MuxEntry ¶
type MuxEntry struct {
// contains filtered or unexported fields
}
func NewMuxEntry ¶
func NewMuxEntry(hostname string, handler http.HandlerFunc, prefix string, handler_type util.HandlerTypeEnum) *MuxEntry