Documentation ¶
Overview ¶
Server package is responsible for creating the server for the baboon application.
Uses: go-chi as router: https://go-chi.io/, alex-edwards scs v2 as session manager: http://github.com/alexedwards/scs/v2
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // MaintenanceMode is used to set the server in maintenance mode (default false) MaintenanceMode bool = false )
Functions ¶
func NewCookie ¶
func NewCookie(c CookieConfig) http.Cookie
TODO: add cookie methods to set, delete, create new cookies returning http.Cookie
Types ¶
type CookieConfig ¶
type CookieConfig struct { // Name defaults to baboon Name string // Domain defaults to localhost Domain string // Lifetime defaults to 1440 minutes LifeTime int // time in minutes // Secure defaults to false Secure bool // Persist defaults to false Persist bool // SameSite defaults to SameSiteStrict mode SameSite http.SameSite }
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware holds all default middleware used by the server.
func (*Middleware) CheckMaintenanceMode ¶
func (m *Middleware) CheckMaintenanceMode(next http.Handler) http.Handler
type Server ¶
type Server struct { // Log is the server's logger Log *logger.Logger // Session holds the server's sessionmanager Session *Session // Renderer is used to render html pages for web routes Renderer *render.Renderer // Middleware holds the default middleware added to a baboon server Middleware *Middleware // Router is the baboon server's router Router *chi.Mux // contains filtered or unexported fields }
func NewServer ¶
func NewServer(sc ServerConfig) (*Server, error)
NewServer returns a new server loaded with the server config.
func (*Server) ActivateMaintenanceMode ¶
func (s *Server) ActivateMaintenanceMode()
ActivateMaintenanceMode is replaced by SetMaintenanceMode. ActivateMaintenceMode calls SetMaintenanceMode true.
func (*Server) SetMaintenanceMode ¶ added in v1.0.3
SetMaintenaceMode sets the server in or out of maintenance mode.
type ServerConfig ¶
type ServerConfig struct { // this is a required field // rootpath is the rootpath of the application using the baboon server, Rootpath string // Debug defaults to false Debug bool // host defaults to localhost Host string // port defaults to 4000 Port string // Renderer defaults to the jet templating engine Renderer string // Cookie cookie configuration Cookie CookieConfig }
ServerConfig stores all configuration variables for a baboon server
TODO: find a way to have a generic cache interface for baboon application
type Session ¶
type Session struct { Manager *scs.SessionManager // contains filtered or unexported fields }
func NewSession ¶
func NewSession(c CookieConfig, s *Server) *Session
New creates and returns a new session manager. Needs a cookieconfig.
func (*Session) SetPersistentStoreBadger ¶
SetPersistentStoreBadger sets the session store to badger
func (*Session) SetPersistentStoreDatabase ¶
SetPersistentStoreDatabase sets the session store to the database, expects required session schema to be present.
The bobo CLI command <bobo make session> can create and execute the corresponding db migration for you. Below example is for postgres, refer to https://github.com/alexedwards/scs#configuring-the-session-store for full documentation.
CREATE TABLE sessions (
token TEXT PRIMARY KEY, data BYTEA NOT NULL, expiry TIMESTAMPTZ NOT NULL
);
CREATE INDEX sessions_expiry_idx ON sessions (expiry);
func (*Session) SetPersistentStoreRedis ¶
SetPersistenStoreRedis sets the session store to redis