Documentation ¶
Index ¶
- type CORSOptions
- type CSRFOptions
- type ContentSecurityPolicy
- type Folders
- type Server
- func (s *Server) AddFlashMessage(w http.ResponseWriter, r *http.Request, value string) error
- func (s *Server) ApplyTemplate(w http.ResponseWriter, name string, data interface{}) error
- func (s *Server) CORS(h http.Handler) http.Handler
- func (s *Server) CSP(h http.Handler) http.Handler
- func (s *Server) CSRF(h http.Handler) http.Handler
- func (s *Server) DB() *sqlx.DB
- func (s *Server) ErrorCheck(err error, w http.ResponseWriter, statusCode int, text string) bool
- func (s *Server) GetCSRF(w http.ResponseWriter, r *http.Request) template.HTML
- func (s *Server) GetCookie(r *http.Request, name string) (string, error)
- func (s *Server) GetCurrentUser(r *http.Request) (User, error)
- func (s *Server) GetDescription() string
- func (s *Server) GetFlashMessages(w http.ResponseWriter, r *http.Request, clear bool) []string
- func (s *Server) GetSession(r *http.Request, key string, defaultValue interface{}) (interface{}, error)
- func (s *Server) JSON(h http.Handler) http.Handler
- func (s *Server) ListenAndServe() error
- func (s *Server) LogoutCurrentUser(w http.ResponseWriter, r *http.Request) error
- func (s *Server) RegisterSessionType(value interface{})
- func (s *Server) RemoveCookie(w http.ResponseWriter, r *http.Request, name string) error
- func (s *Server) ServerErrorCheck(err error, w http.ResponseWriter, r *http.Request) bool
- func (s *Server) SetCookie(w http.ResponseWriter, name string, value string, minutes int) error
- func (s *Server) SetCurrentUser(w http.ResponseWriter, r *http.Request, user User) error
- func (s *Server) SetSession(w http.ResponseWriter, r *http.Request, key string, value interface{}) error
- func (s *Server) SetStatus(w http.ResponseWriter, statusCode int, text string)
- func (s *Server) UsersOnly(h http.Handler) http.Handler
- func (s *Server) XML(h http.Handler) http.Handler
- type ServerConfig
- type SessionOptions
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CORSOptions ¶
type CORSOptions struct {
Origins, Methods, Headers []string
}
CORSOptions ... Defines the options for the CORS headers.
type CSRFOptions ¶
CSRFOptions ... Defines the options for the CSRF token.
type ContentSecurityPolicy ¶
type ContentSecurityPolicy struct {
Default, Script, Style, Font []string
}
ContentSecurityPolicy ... Defines the CSP for header generation.
type Folders ¶
type Folders struct {
Templates, LetsEncrypt, StaticContent string
}
Folders ... Details various file system locations.
type Server ¶
type Server struct { HTTPServer *http.Server Router *mux.Router Config ServerConfig // contains filtered or unexported fields }
Server ... Holds all the config and running instance of the web server.
func NewServer ¶
func NewServer(config ServerConfig) Server
NewServer ... Creates a new server with hostname router etc.
func (*Server) AddFlashMessage ¶
AddFlashMessage ... Adds a one-time flash message to the session.
func (*Server) ApplyTemplate ¶
func (s *Server) ApplyTemplate(w http.ResponseWriter, name string, data interface{}) error
ApplyTemplate ... Writes the named template with the given data.
func (*Server) ErrorCheck ¶
ErrorCheck ... If there is an error, send it (with status/text) and return true. If the error template is switched on then it skips the header and passes on the details.
func (*Server) GetCSRF ¶
GetCSRF ... Gets a request-specific CSRF token (also placed into a cookie for CSRF middleware checks).
func (*Server) GetCurrentUser ¶
GetCurrentUser ... Gets the user from a secure cookie (0 for none).
func (*Server) GetDescription ¶
GetDescription ... Gets a simple string description of the server (for UI purposes).
func (*Server) GetFlashMessages ¶
GetFlashMessages ... Gets the one-time flash messages from the session. Deliberately not returning an error for ease of use.
func (*Server) GetSession ¶
func (s *Server) GetSession(r *http.Request, key string, defaultValue interface{}) (interface{}, error)
GetSession ... Gets a (secure cookie) session value.
func (*Server) ListenAndServe ¶
ListenAndServe ... Serves on configured port, with auto-HTTPS for port 443.
func (*Server) LogoutCurrentUser ¶
LogoutCurrentUser ... Removes the secure cookie for the user.
func (*Server) RegisterSessionType ¶
func (s *Server) RegisterSessionType(value interface{})
RegisterSessionType ... Registers a type for use in sessions.
func (*Server) RemoveCookie ¶
RemoveCookie ... Removes a secure cookie.
func (*Server) ServerErrorCheck ¶
ServerErrorCheck ... If there is an error, send it (as a 500) and return true. If the error template is switched on then it skips the header and passes on the details.
func (*Server) SetCurrentUser ¶
SetCurrentUser ... Sets the user in a secure cookie; use 0 for none.
func (*Server) SetSession ¶
func (s *Server) SetSession(w http.ResponseWriter, r *http.Request, key string, value interface{}) error
SetSession ... Sets a (secure cookie) session value.
func (*Server) SetStatus ¶
func (s *Server) SetStatus(w http.ResponseWriter, statusCode int, text string)
SetStatus ... Issues a standard status code/text and continues. If the error template is switched on then it skips the header and passes on the details.
type ServerConfig ¶
type ServerConfig struct {
Hostname, StaticPath string
Port int
Logger io.Writer
LogToStdout, HandlePanic bool
LoginRoute, ErrorTemplate string
Folders Folders
SessionOptions SessionOptions
CSRFOptions CSRFOptions
CORSOptions CORSOptions
CSPOptions ContentSecurityPolicy
DBConnectionString string
}
ServerConfig ... Defines the server behaviour.
func LoadServerConfig ¶
func LoadServerConfig(filename string) (ServerConfig, error)
LoadServerConfig ... Loads from the specified file (ini format).
type SessionOptions ¶
SessionOptions ... Defines the options for sessions.