Documentation ¶
Index ¶
- func AdjustPage(page int) int
- func HasNextPage(page, pageSize, recordCount int) bool
- func NewBasicWebAppRouterAndServer(config BasicWebAppConfig) (*mux.Router, *http.Server)
- func NewBasicWebAppServer(router *mux.Router, config BasicWebAppConfig) *http.Server
- func NewRESTRouterAndServer(config RESTConfig) (*mux.Router, *http.Server)
- func NewRESTServer(router *mux.Router, config RESTConfig) *http.Server
- func NewSPARouterAndServer(config SPAConfig) (*mux.Router, *http.Server)
- func NewSPAServer(router *mux.Router, config SPAConfig) *http.Server
- func ReadJSONBody(r *http.Request, dest interface{}) error
- func RealIP(r *http.Request) string
- func TotalPages(pageSize, recordCount int) int
- func ValidateHTTPMethod(r *http.Request, w http.ResponseWriter, expectedMethod string, ...) error
- func WaitForKill() chan os.Signal
- func WriteJSON(logger *logrus.Entry, w http.ResponseWriter, status int, value interface{})
- func WriteString(logger *logrus.Entry, w http.ResponseWriter, status int, value string)
- type BasicWebAppConfig
- type Endpoint
- type Endpoints
- type RESTConfig
- type SPAConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdjustPage ¶
AdjustPage decrements the value of "page" because we want to use zero-based pages for the math. Make sure page is never less than zero.
func HasNextPage ¶
HasNextPage returns true when the result of page multiplied by pageSize is less than the total recordCount.
func NewBasicWebAppRouterAndServer ¶ added in v2.3.0
func NewBasicWebAppRouterAndServer(config BasicWebAppConfig) (*mux.Router, *http.Server)
NewBasicWebAppRouterAndServer creates a new Gorilla router and HTTP server with some preconfigured defaults for basic web applications. The HTTP server is setup to use the resulting router.
func NewBasicWebAppServer ¶ added in v2.3.0
func NewBasicWebAppServer(router *mux.Router, config BasicWebAppConfig) *http.Server
NewBasicWebAppServer accepts an existing Gorilla router and returns an HTTP server with some preconfigured defaults for a basic web application. The HTTP server is setup to use the resulting router.
func NewRESTRouterAndServer ¶
func NewRESTRouterAndServer(config RESTConfig) (*mux.Router, *http.Server)
NewRESTRouterAndServer creates a new Gorilla router and HTTP server with some preconfigured defaults for REST applications. The HTTP server is setup to use the resulting router.
func NewRESTServer ¶
func NewRESTServer(router *mux.Router, config RESTConfig) *http.Server
NewRESTServer accepts an existing Gorilla router and returns an HTTP server with some preconfigured defaults for REST applications. The HTTP server is setup to use the resulting router.
func NewSPARouterAndServer ¶
NewSPARouterAndServer creates a new Gorilla router and HTTP server with some preconfigured defaults for single page applications. The HTTP server is setup to use the resulting router.
func NewSPAServer ¶
NewSPAServer accepts an existing Gorilla router and returns an HTTP server with some preconfigured defaults for a single page application. The HTTP server is setup to use the resulting router.
func ReadJSONBody ¶
ReadJSONBody reads the body content from an http.Request as JSON data into dest.
func RealIP ¶
RealIP attempts to return the IP address of the caller. The result will default to the RemoteAddr from http.Request. It will also check the request headers for an "X-Forwarded-For" value and use that. This is useful for when requests come through proxies or other non-direct means.
func TotalPages ¶
TotalPages returns how many pages are available in a paged result based pageSize and the total recordCount.
func ValidateHTTPMethod ¶
func ValidateHTTPMethod(r *http.Request, w http.ResponseWriter, expectedMethod string, logger *logrus.Entry) error
ValidateHTTPMethod checks the request METHOD against expectedMethod. If they do not match an error message is written back to the client.
func WaitForKill ¶
WaitForKill returns a channel that waits for an OS interrupt or terminate.
func WriteJSON ¶
func WriteJSON(logger *logrus.Entry, w http.ResponseWriter, status int, value interface{})
WriteJSON writes JSON content to the response writer.
func WriteString ¶
WriteString writes string content to the response writer.
Types ¶
type BasicWebAppConfig ¶ added in v2.3.0
type BasicWebAppConfig struct { AppDirectory string AppFileSystem embed.FS Endpoints Endpoints Host string IdleTimeout int ReadTimeout int Version string WriteTimeout int }
BasicWebAppConfig is used to configure a Go template web application router
func DefaultBasicWebAppConfig ¶ added in v2.3.0
func DefaultBasicWebAppConfig(host, version string, appFileSystem embed.FS) BasicWebAppConfig
DefaultBasicWebAppConfig creates a basic web application configuration with default values. In this configuration the directory holding the front-end JavaScript and CSS is "app". The HTTP server is configured with an idle timeout of 60 seconds, and a read and write timeout of 30 seconds.
type Endpoint ¶
type Endpoint struct { Path string Methods []string HandlerFunc http.HandlerFunc Handler http.Handler }
Endpoint defines a single HTTP endpoint. Each endpoint is used to configure a Gorilla Mux route.
type RESTConfig ¶
type RESTConfig struct { Endpoints Endpoints Host string IdleTimeout int ReadTimeout int WriteTimeout int }
RESTConfig is used to configure a router for basic REST servers
func DefaultRESTConfig ¶
func DefaultRESTConfig(host string) RESTConfig
DefaultRESTConfig creates a REST configuration with default values. In this configuration the HTTP server is configured with an idle timeout of 60 seconds, and a read and write timeout of 30 seconds.
type SPAConfig ¶
type SPAConfig struct { AppDirectory string AppFileSystem embed.FS Endpoints Endpoints Host string IdleTimeout int IndexHTML []byte MainJS []byte ManifestJSON []byte ReadTimeout int Version string WriteTimeout int }
SPAConfig is used to configure a single page application router
func DefaultSPAConfig ¶
func DefaultSPAConfig(host, version string, appFileSystem embed.FS, indexHTML, mainJS, manifestJSON []byte) SPAConfig
DefaultSPAConfig creates a single page application configuration with default values. In this configuration the directory holding the front-end application is "app". The HTTP server is configured with an idle timeout of 60 seconds, and a read and write timeout of 30 seconds.