server

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 23 Imported by: 0

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

View Source
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

func (*Middleware) NoSurf

func (m *Middleware) NoSurf(next http.Handler) http.Handler

NoSurf is the middleware required to implement CSRF protection.

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) Run

func (s *Server) Run() error

func (*Server) SetMaintenanceMode added in v1.0.3

func (s *Server) SetMaintenanceMode(on bool)

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

func (s *Session) SetPersistentStoreBadger(badger *badger.DB)

SetPersistentStoreBadger sets the session store to badger

func (*Session) SetPersistentStoreDatabase

func (s *Session) SetPersistentStoreDatabase(dialect string, driver *sql.DB) error

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

func (s *Session) SetPersistentStoreRedis(pool *redis.Pool)

SetPersistenStoreRedis sets the session store to redis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL