Documentation ¶
Overview ¶
Package forest provides a minimalist framework for writing REST services that speak JSON.
Index ¶
- Constants
- type App
- func (app *App) Duration(key string) time.Duration
- func (app *App) Error(key string) string
- func (app *App) InstallWare(key string, handler func(ctx *bear.Context), message string) error
- func (app *App) ListenAndServe() error
- func (app *App) ListenAndServeTLS(certFile, keyFile string) error
- func (app *App) Message(key string) string
- func (app *App) On(verb string, pattern string, handlers ...interface{}) error
- func (app *App) RegisterRoute(path string, sub SubRouter)
- func (app *App) Response(ctx *bear.Context, code int, success bool, message string) *Response
- func (app *App) SetCookie(ctx *bear.Context, path, key, value string, duration time.Duration)
- func (app *App) SetDuration(key string, value time.Duration)
- func (app *App) SetError(key string, value string)
- func (app *App) SetMessage(key string, value string)
- func (app *App) Ware(key string) func(ctx *bear.Context)
- type Config
- type Response
- type SubRouter
Constants ¶
const ( Body = "forestbody" DurationCookie = 26 * time.Hour DurationSession = 25 * time.Hour ErrorBadCredentials = "bad credentials" ErrorCSRF = SessionID + " required" ErrorGeneric = "something went wrong" ErrorMethodNotAllowed = "method not allowed" ErrorNotFound = "not found" ErrorParse = "json parse error" Failure = false Success = true NoMessage = "" SessionID = "sessionid" SessionRefresh = "sessionrefresh" SessionUser = "sessionuser" SessionUserID = "sessionuserid" Error = "foresterror" SafeError = "forestsafeerror" UnknownIP = "unknown-ip" UnknownAgent = "unknown user agent" UnknownSession = "unknown-session" WareInstalled = "forest middleware" )
const ConfigFile = "forest.json"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct { *bear.Mux Config *Config Log *logger.Logger SafeErrorFilter func(error) error // contains filtered or unexported fields }
func (*App) InstallWare ¶
func (*App) ListenAndServe ¶
func (*App) ListenAndServeTLS ¶
func (*App) RegisterRoute ¶
func (*App) SetDuration ¶
SetDuration sets the duration for a specific key, e.g. "Cookie" expiration.
func (*App) SetMessage ¶
SetMessage sets the app message for a specific key, e.g. "AlreadyLoggedIn".
type Config ¶
type Config struct { Address string `json:"address,omitempty"` CookiePath string File string LogLevel int LogLevelName string `json:"loglevel,omitempty"` LogRequests bool `json:"logrequests,omitempty"` Name string `json:"name,omitempty"` PoweredBy string Debug bool `json:"debug,omitempty"` Version string `json:"version,omitempty"` }
type Response ¶
type Response struct { Data interface{} `json:"data,omitempty"` Success bool `json:"success"` Message string `json:"message,omitempty"` // contains filtered or unexported fields }
type SubRouter ¶
type SubRouter interface {
Route(path string)
}
SubRouter is the basic building block of forest applications. In the main.go file where a service is initialized, app.RegisterRoute is called with a path string and a SubRouter instance in order to logically group all of the endpoints a particular service will answer. Since each App inherits from bear.Mux , it is not strictly necessary to use SubRouter at all, it simply exists to provide a convenient way to instantiate many endpoints in one place.