Documentation ¶
Overview ¶
Package server is a wrapper around the stdlib http server and x/autocert pkg.
Index ¶
- func AddCacheHeaders(w http.ResponseWriter, days int, hash string)
- func Redirect(w http.ResponseWriter, r *http.Request, path string) error
- func RedirectExternal(w http.ResponseWriter, r *http.Request, path string) error
- func RedirectStatus(w http.ResponseWriter, r *http.Request, path string, status int) error
- type Logger
- type Server
- func (s *Server) Config(key string) string
- func (s *Server) ConfigBool(key string) bool
- func (s *Server) ConfigInt(key string) int64
- func (s *Server) Configuration() map[string]string
- func (s *Server) ConfiguredTLSServer(certManager *autocert.Manager) *http.Server
- func (s *Server) Fatal(format string)
- func (s *Server) Fatalf(format string, v ...interface{})
- func (s *Server) Log(message string)
- func (s *Server) Logf(format string, v ...interface{})
- func (s *Server) Mode() string
- func (s *Server) Port() int
- func (s *Server) PortString() string
- func (s *Server) Production() bool
- func (s *Server) SetProduction(value bool)
- func (s *Server) Start() error
- func (s *Server) StartRedirectAll(p int, host string)
- func (s *Server) StartTLS(cert, key string) error
- func (s *Server) StartTLSAuto(email, domains string) error
- func (s *Server) StartTLSAutocert(email string, domains string) error
- func (s *Server) Timef(format string, start time.Time, v ...interface{})
- type StatusError
- func BadRequestError(e error, args ...string) *StatusError
- func Error(e error, s int, t string, m string) *StatusError
- func InternalError(e error, args ...string) *StatusError
- func NotAuthorizedError(e error, args ...string) *StatusError
- func NotFoundError(e error, args ...string) *StatusError
- func ToStatusError(e error) *StatusError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCacheHeaders ¶
func AddCacheHeaders(w http.ResponseWriter, days int, hash string)
AddCacheHeaders adds Cache-Control, Expires and Etag headers using the age in days and content hash provided
func Redirect ¶
Redirect uses status 302 StatusFound by default - this is not a permanent redirect We don't accept external or relative paths for security reasons
func RedirectExternal ¶
RedirectExternal redirects setting the status code (for example unauthorized), but does no checks on the path Use with caution and only on paths *fixed at compile time*.
func RedirectStatus ¶
RedirectStatus redirects setting the status code (for example unauthorized) We don't accept external or relative paths for security reasons
Types ¶
type Logger ¶
type Logger interface {
Printf(format string, args ...interface{})
}
Logger interface for a logger - deprecated for 2.0
type Server ¶
type Server struct { // Deprecated Logging - due to be removed in 2.0 // Instead use the structured logging with server/log Logger Logger // contains filtered or unexported fields }
Server wraps the stdlib http server and x/autocert pkg with some setup.
func (*Server) ConfigBool ¶
ConfigBool returns the current configuration value as bool (yes=true, no=false), or false if no value
func (*Server) ConfigInt ¶
ConfigInt returns the current configuration value as int64, or 0 if no value
func (*Server) Configuration ¶
Configuration returns the map of configuration keys to values
func (*Server) ConfiguredTLSServer ¶
ConfiguredTLSServer returns a TLS server instance with a secure config this server has read/write timeouts set to 20 seconds, prefers server cipher suites and only uses certain accelerated curves see - https://blog.gopheracademy.com/advent-2016/exposing-go-on-the-internet/
func (*Server) Fatalf ¶
Fatalf the message with the given arguments to our internal logger, and then exits with status 1
func (*Server) PortString ¶
PortString returns a string port suitable for passing to http.Server
func (*Server) Production ¶
Production tells the caller if this server is in production mode or not?
func (*Server) SetProduction ¶
SetProduction sets the mode manually to SetProduction
func (*Server) StartRedirectAll ¶
StartRedirectAll starts redirecting all requests on the given port to the given host this should be called before StartTLS if redirecting http on port 80 to https
func (*Server) StartTLS ¶
StartTLS starts an https server on the given port with tls cert/key from config keys. Settings based on an article by Filippo Valsorda. https://blog.cloudflare.com/exposing-go-on-the-internet/
func (*Server) StartTLSAuto ¶
StartTLSAuto starts an https server on the given port by requesting certs from an ACME provider using the http-01 challenge. it also starts a server on the port 80 to listen for challenges and redirect The server must be on a public IP which matches the DNS for the domains.
func (*Server) StartTLSAutocert ¶
StartTLSAutocert starts an https server on the given port by requesting certs from an ACME provider. The server must be on a public IP which matches the DNS for the domains.
type StatusError ¶
StatusError wraps a std error and stores more information (status code, display title/msg and caller info)
func BadRequestError ¶
func BadRequestError(e error, args ...string) *StatusError
BadRequestError returns a new StatusError with Status StatusBadRequest and optional Title and Message
func Error ¶
func Error(e error, s int, t string, m string) *StatusError
Error returns a new StatusError with code StatusInternalServerError and a generic message
func InternalError ¶
func InternalError(e error, args ...string) *StatusError
InternalError returns a new StatusError with Status StatusInternalServerError and optional Title and Message Usage: return router.InternalError(err)
func NotAuthorizedError ¶
func NotAuthorizedError(e error, args ...string) *StatusError
NotAuthorizedError returns a new StatusError with Status StatusUnauthorized and optional Title and Message
func NotFoundError ¶
func NotFoundError(e error, args ...string) *StatusError
NotFoundError returns a new StatusError with Status StatusNotFound and optional Title and Message Usage return router.NotFoundError(err,"Optional Title", "Optional user-friendly Message")
func ToStatusError ¶
func ToStatusError(e error) *StatusError
ToStatusError returns a *StatusError or wraps a standard error in a 500 StatusError
func (*StatusError) Error ¶
func (e *StatusError) Error() string
Error returns the underling error string - it should not be shown in production
func (*StatusError) FileLine ¶
func (e *StatusError) FileLine() string
FileLine returns file name and line of error
func (*StatusError) String ¶
func (e *StatusError) String() string
String returns a string represenation of this error, useful for debugging
Directories ¶
Path | Synopsis |
---|---|
Package config offers utilities for parsing a json config file.
|
Package config offers utilities for parsing a json config file. |
Package log provides a structured, levelled logger interface for use in server handlers, which handles multiple output streams.
|
Package log provides a structured, levelled logger interface for use in server handlers, which handles multiple output streams. |
Package schedule provides a simple way to schedule functions at a time or interval
|
Package schedule provides a simple way to schedule functions at a time or interval |