Documentation ¶
Overview ¶
* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *
* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *
* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *
* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *
* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *
Index ¶
- Constants
- Variables
- func Authenticate(db *connectordb.Database, request *http.Request) (o *authoperator.AuthOperator, err error)
- func CreateSessionCookie(o *authoperator.AuthOperator, writer http.ResponseWriter, ...) error
- func GetFuncName(apifunc APIHandler) string
- func GetRequestLogger(request *http.Request, opname string) *log.Entry
- func GetStreamPath(request *http.Request) (username string, devicename string, streamname string, streampath string)
- func HandlePanic(logger *log.Entry)
- func HasSession(request *http.Request) bool
- func Initialize(c *config.Configuration) error
- func LogRequest(l *log.Entry, loglevel int, txt string, tdiff time.Duration)
- func RunQueryTimers()
- func RunStats()
- func SetEnabled(v bool)
- func Shutdown()
- func StatsAddFail(err error)
- func WriteAccessControlHeaders(writer http.ResponseWriter, request *http.Request)
- type APIHandler
- type QueryTimer
- type WebContext
Constants ¶
const ( DEBUG = iota INFO = iota WARNING = iota ERROR = iota )
Log levels supported by LogRequest
Variables ¶
var ( // ErrNoAuthentication is an error that is thrown when no authentication is given ErrNoAuthentication = errors.New("No authentication given with request") //CookieMonster is the handler for authentication based on cookies CookieMonster *securecookie.SecureCookie )
var ( //The following globals are atomically incremented/decremnted to give statistics StatsAuthFails = uint32(0) StatsRESTQueries = uint32(0) StatsWebQueries = uint32(0) StatsInserts = uint32(0) StatsErrors = uint32(0) StatsPanics = uint32(0) StatsActive = int32(0) QueryTimers = make(map[string]*QueryTimer) )
var ( //The name of the site. SiteName string //AllowCrossOrigin: Whether or not cross origin requests are permitted AllowCrossOrigin = false //IsActive - no need for sync, really. It specifies if the server should accept connections. IsActive = true //ShutdownChannel is a shared channel which is used when a shutdown is signalled. //Each goroutine that uses the ShutdownChannel is to IMMEDIATELY refire the channel before doing anything else, //so that the signal continues throughout the system ShutdownChannel = make(chan bool, 1) )
Functions ¶
func Authenticate ¶
func Authenticate(db *connectordb.Database, request *http.Request) (o *authoperator.AuthOperator, err error)
Authenticate gets the authenticated device Operator given an http.Request
func CreateSessionCookie ¶
func CreateSessionCookie(o *authoperator.AuthOperator, writer http.ResponseWriter, request *http.Request) error
CreateSessionCookie generates the authentication cookie from an authenticated user
func GetFuncName ¶
func GetFuncName(apifunc APIHandler) string
GetFuncName returns the name of the function that is going to handle a request
func GetRequestLogger ¶
GetRequestLogger returns a logrus log entry which has fields prepopulated for the request
func GetStreamPath ¶
func GetStreamPath(request *http.Request) (username string, devicename string, streamname string, streampath string)
GetStreamPath returns the relevant parts of a stream path
func HandlePanic ¶
HandlePanic is called in defer statements to handle a panic within a request. It is assumed that the connection is active
func HasSession ¶
HasSession returns whether there is a session cookie with this request
func Initialize ¶
func Initialize(c *config.Configuration) error
Initialize sets up the necessary global state of WebCore such that it fits the given configuration. Note that it is called in a config change callback, and does not use locking of state, so some weird bugs might be possible if config is reloaded frequently during heavy load
func LogRequest ¶
LogRequest writes a log message given the log entry to use, a log level, optional text, and the query duration
func RunQueryTimers ¶
func RunQueryTimers()
RunQueryTimers periodically gets and prints the query average runtime and variance
func RunStats ¶
func RunStats()
RunStats periodically displays query amounts and relevant data. It does not display anything if there was no action within a time period.
func SetEnabled ¶
func SetEnabled(v bool)
SetEnabled allows to enable and disable acceptance of connections in a simple way
func StatsAddFail ¶
func StatsAddFail(err error)
StatsAddFail adds an authentication failure to the statistics
func WriteAccessControlHeaders ¶
func WriteAccessControlHeaders(writer http.ResponseWriter, request *http.Request)
WriteAccessControlHeaders writes the access control headers for the site
Types ¶
type APIHandler ¶
type APIHandler func(o *authoperator.AuthOperator, writer http.ResponseWriter, request *http.Request, logger *log.Entry) (int, string)
APIHandler is a function that handles some part of the REST API given a specific operator on the database.
type QueryTimer ¶
type QueryTimer struct { sync.Mutex //TimeSum is the total sum of times that the given query ran TimeSum float64 //TimeVarSum is the sum of squares of times that the given query ran TimeVarSum float64 //NumQueries is the number of queries that were handled in the given time period NumQueries int32 }
QueryTimer holds timing statistics for a specific query
func GetQueryTimer ¶
func GetQueryTimer(funcname string) *QueryTimer
GetQueryTimer gets a query timer. Simple
type WebContext ¶
type WebContext struct { Operator operator.Operator Writer http.ResponseWriter Request *http.Request Logger *log.Entry }
Provides utilities and information about the current web request.
func (*WebContext) GetDeviceName ¶
func (wc *WebContext) GetDeviceName() string
Returns the device name submitted by the request
func (*WebContext) GetDevicePath ¶
func (wc *WebContext) GetDevicePath() string
func (*WebContext) GetStreamName ¶
func (wc *WebContext) GetStreamName() string
Returns the stream name submitted by the request
func (*WebContext) GetStreamPath ¶
func (wc *WebContext) GetStreamPath() string
func (*WebContext) GetUsername ¶
func (wc *WebContext) GetUsername() string
Returns the username submitted by the request