Documentation ¶
Index ¶
- Variables
- func Close()
- func ErrorResponse(w http.ResponseWriter, s int, f string, args ...interface{})
- func GZIPJSONResponse(w http.ResponseWriter, data interface{})
- func Init(dsn string) error
- func InitDebug(dsn string, debug bool) error
- func IsValidStatus(r *http.Response, codes ...int) bool
- func JSONResponse(w http.ResponseWriter, data interface{})
- func LinkOrCopy(src, dest string) (err error)
- func ParseIDs(url string, re *regexp.Regexp, ids ...*int) int
- func Pool() db.DB
- func WithLog(f http.HandlerFunc) http.HandlerFunc
- func WithMethods(args ...interface{}) http.HandlerFunc
- type Data
- type HandlerFunc
Constants ¶
This section is empty.
Variables ¶
var MaxRetries = 10
MaxRetries defines the number of times wait tries to connect to the database. Zero means unlimited retries.
var Wait = 2 * time.Second
Wait defines the time to wait between retries for the database connection.
Functions ¶
func ErrorResponse ¶
func ErrorResponse(w http.ResponseWriter, s int, f string, args ...interface{})
ErrorResponse writes an error response. It sets the according response header and sends a json-formatted response object.
func GZIPJSONResponse ¶ added in v0.2.9
func GZIPJSONResponse(w http.ResponseWriter, data interface{})
GZIPJSONResponse writes a gzipped json-formatted response. Any errors are being logged.
func Init ¶
Init sets up the database connection pool using the supplied DSN `user:pass@proto(host/dbname`. Init waits for the databsase to be online. It is not save to call Init from different go routines.
func InitDebug ¶ added in v0.4.3
InitDebug sets up the database connection pool using the supplied DSN `user:pass@proto(host/dbname` and sets the log level to debug if debug=true. It then calls Init(dsn) and returns its result.
func IsValidStatus ¶
IsValidStatus returns true if the given response has any of the given status codes.
func JSONResponse ¶
func JSONResponse(w http.ResponseWriter, data interface{})
JSONResponse writes a json-formatted response. Any errors are being logged.
func LinkOrCopy ¶ added in v0.2.5
LinkOrCopy tries to hard link dest to src. If the file or link already exists nothing is done and no error is returned. If the linking fails, LinkOrCopy tries to copy src to dest.
func ParseIDs ¶
ParseIDs parses the numeric fields of the given regex into the given id pointers. It returns the number of ids parsed.
func WithLog ¶
func WithLog(f http.HandlerFunc) http.HandlerFunc
WithLog wraps logging around the handling of the request.
func WithMethods ¶
func WithMethods(args ...interface{}) http.HandlerFunc
WithMethods dispatches a given pair of the request methods to the given HandlerFunc with an empty data context. The first element must be of type string, the second argument must be of type HandlerFunc. The function panics if it encounteres an invalid type.
Types ¶
type Data ¶
type Data struct { Session *api.Session // authentification information Project *db.Project // requested project Post interface{} // post data IDs map[string]int // ids }
Data defines the payload data for request handlers.
type HandlerFunc ¶
HandlerFunc defines the callback function to handle callbacks with data.
func WithAuth ¶
func WithAuth(f HandlerFunc) HandlerFunc
WithAuth checks if the given request contains a valid authentication token. If not an appropriate error is returned before the given callback function is called. If the authentification succeeds, the session is put into the context as "auth".
func WithIDs ¶ added in v0.2.5
func WithIDs(f HandlerFunc, keys ...string) HandlerFunc
WithIDs fills the IDs map with the given (key,id) pairs or returns status not found if the given ids could not be parsed in the given order. You can prefix a key with `?` to mark it optional (the key is then not inserted intot the ID map if it is not present in the request's URL).
func WithProject ¶
func WithProject(f HandlerFunc) HandlerFunc
WithProject loads the project data for the given project id and puts it into the context using "project" as key. Then it calls the given handler function.
func WithUser ¶ added in v0.5.0
func WithUser(f HandlerFunc) HandlerFunc
WithUser extracts the "/users/<numeric id>" part from the url, loads it and puts it into the context with the key "user".