Documentation ¶
Index ¶
- Constants
- func AddRoute(pattern string, handler func(http.ResponseWriter, *http.Request), ...)
- func AddRoutes(r ...route)
- func AddStaticRoute(prefix, dir string)
- func ErrPageHandler(w http.ResponseWriter, _ *http.Request, status int, info interface{})
- func GetBrowserOpenPage() string
- func GetMySQLDBName() string
- func GetMySQLDataSrc() string
- func GetMySQLDriver() string
- func GetMySQLExtra() string
- func GetMySQLPassword() string
- func GetMySQLUrl() string
- func GetMySQLUsername() string
- func GetServerName() string
- func GetServerPort() int
- func GetServerTimeout() int64
- func GetSessionCookieName() string
- func GetSessionProviderName() string
- func GetSessionTimeout() int64
- func IsBrowserAutoOpen() bool
- func LoadConfig(filename string)
- func NewRoute(pattern string, handler func(http.ResponseWriter, *http.Request), ...) *route
- func NewServer() *crimsonServer
- func OpenInBrowser()
- func OpenUrlInBrowser(url string)
- func PrintError(contents ...interface{})
- func PrintInfo(contents ...interface{})
- func PrintWarning(contents ...interface{})
- func SetDefaultErrPageHandler(...)
- func SetLogPrintServerName(val bool)
- type Session
- type SessionManager
Constants ¶
const (
// Version is the current version of Crimson
Version = "1.0"
)
Variables ¶
This section is empty.
Functions ¶
func AddStaticRoute ¶
func AddStaticRoute(prefix, dir string)
AddStaticRoute configures static file server, e.g. css and js files.
func ErrPageHandler ¶
func ErrPageHandler(w http.ResponseWriter, _ *http.Request, status int, info interface{})
ErrPageHandler sets response status code and error page.
func GetBrowserOpenPage ¶
func GetBrowserOpenPage() string
GetBrowserOpenPage returns open page name for browser auto open
func GetMySQLDBName ¶
func GetMySQLDBName() string
func GetMySQLDataSrc ¶
func GetMySQLDataSrc() string
GetMySQLDataSrc returns MySQL data source in format of username:password@url/db?extra
func GetMySQLDriver ¶
func GetMySQLDriver() string
GetMySQLDriver returns MySQL driver name (usually mysql, mariadb is also available for mariadb)
func GetMySQLUrl ¶
func GetMySQLUrl() string
GetMySQLUrl returns MySQL URL in format of ip_address:port_number
func GetServerName ¶
func GetServerName() string
GetServerName returns application name that configured in config.yml or default value
func GetServerPort ¶
func GetServerPort() int
GetServerPort returns port number that configured in config.yml or default value.
func GetServerTimeout ¶
func GetServerTimeout() int64
GetServerTimeout returns server shut down timeout in uint of second that configured in config.yml or default value.
func GetSessionCookieName ¶
func GetSessionCookieName() string
GetSessionCookieName returns cookie name for session that configured in config.yml or default value.
func GetSessionProviderName ¶
func GetSessionProviderName() string
GetSessionProviderName returns session provider name that configured in config.yml or default value.
func GetSessionTimeout ¶
func GetSessionTimeout() int64
GetSessionTimeout returns session maximum life time that configured in config.yml or default value.
func IsBrowserAutoOpen ¶
func IsBrowserAutoOpen() bool
IsBrowserAutoOpen returns if open browser automatically after starting server
func LoadConfig ¶
func LoadConfig(filename string)
LoadConfig reads file to load config. If failed to load, use the default values.
func NewRoute ¶
func NewRoute(pattern string, handler func(http.ResponseWriter, *http.Request), methods ...string) *route
NewRoute creates new route instance. Available methods will be GET if not entered.
func OpenInBrowser ¶
func OpenInBrowser()
OpenInBrowser opens http://127.0.0.1:<port><page> in default browser
func OpenUrlInBrowser ¶
func OpenUrlInBrowser(url string)
OpenUrlInBrowser opens URL in default browser
func PrintError ¶
func PrintError(contents ...interface{})
PrintError displays red error in console.
func PrintInfo ¶
func PrintInfo(contents ...interface{})
PrintInfo displays green information in console.
func PrintWarning ¶
func PrintWarning(contents ...interface{})
PrintWarning displays yellow warnings in console.
func SetDefaultErrPageHandler ¶
func SetDefaultErrPageHandler(handler func(w http.ResponseWriter, r *http.Request, status int, info interface{}))
SetDefaultErrPageHandler sets default error page handler.
func SetLogPrintServerName ¶
func SetLogPrintServerName(val bool)
SetLogPrintServerName sets if print server name when print logs
Types ¶
type Session ¶
type Session interface { Set(key, value interface{}) Get(key interface{}) interface{} Delete(key interface{}) SessionID() string }
Session is an interface with methods of set, get, delete, and get session ID.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager for managing sessions.
func NewSessionManager ¶
func NewSessionManager() *SessionManager
NewSessionManager creates new instance for SessionManager
func (*SessionManager) DestroySession ¶
func (m *SessionManager) DestroySession(w http.ResponseWriter, r *http.Request)
DestroySession destroys session by making cookie expired.
func (*SessionManager) StartSession ¶
func (m *SessionManager) StartSession(w http.ResponseWriter, r *http.Request) (session Session)
StartSession starts session according to session ID stored in cookie. If cookie not set or session id is empty, start a new session. Otherwise, use read session by ID.