Documentation
¶
Index ¶
- Constants
- Variables
- func Base64Encode(bv []byte) string
- func Clean(val string) string
- func Run()
- func SHA1(input string) []byte
- func ServeFile(out Output, path string)
- type App
- type Context
- type Input
- type Module
- type Output
- type Route
- func (route *Route) CSRF(emit, need bool) *Route
- func (route *Route) JSON() *Route
- func (route *Route) Match(nameA, nameB string) *Route
- func (route *Route) Need(fields ...string) *Route
- func (route *Route) NoCache() *Route
- func (route *Route) RateLimit(rate, per float32) *Route
- func (route *Route) RateLimitAuth(rate, per float32) *Route
- func (route *Route) ReqAuth(args ...string) *Route
- type RouteFunc
- type Router
Constants ¶
const ( MIME_JSON = `application/json; charset=UTF-8` MIME_HTML = `text/html; charset=UTF-8` )
const ( Response_Ok = 200 Response_Created = 201 Response_Bad_Request = 400 Response_Forbidden = 403 Response_Not_Found = 404 Response_Unsupported_Media_Type = 415 Response_Unprocessable_Entity = 422 Response_Too_Many_Requests = 429 Response_Internal_Server_Error = 500 )
const ( HeaderXRateLimit = `X-Rate-Limit-Limit` HeaderXRateLimitRemaining = `X-Rate-Limit-Remaining` )
const (
ContentType_JSON = "application/json"
)
Variables ¶
var APP = &App{Router: NewRouter()} // default application
Default application handler
var DefaultConfig = newConfigStruct()
Default global configuration
Functions ¶
func Base64Encode ¶
Types ¶
type App ¶
type App struct { Router Config *configStruct // TODO: for each there is application specific configuration // contains filtered or unexported fields }
App structure represents single application on server server can route multiple applications, in different sub-directory or sub-domain
type Context ¶
Context interface combines input and output interfaces so that RouteFunc accepts single parameter - Context
type Input ¶
type Input interface { App() *App RequestURI() string // Get used for getting GET passed parameters Get(key string) (val string) // Returns method of request (GET, POST, PUT, ...) Method() string // Returns header value HeaderValue(string) string ContentType() string // wrapper for http.Request.FormValue FormValue(string) string CookieValue(string) (string, bool) // Return user agent UserAgent() string // Returns remote IP address RemoteAddr() string // Returns true if request is marked as AJAX based Ajax() bool // Access to URL parameters Args(int) t.T // Access to posted data Data() t.Map // Provides access to session data Session() *session.Session // returns body content, JSON post with JSON as content-body Body() (result string) Request() *http.Request // contains filtered or unexported methods }
Input is interface for routes input handler
type Output ¶
type Output interface { // writing function Write([]byte) (n int, err error) WriteString(string) (n int, err error) WriteJSON(interface{}) []byte // response config SetContentType(string) Response(int) // some heper functions SetCookieValue(string, string) Redirect(url ...string) AddHeader(string, interface{}) Header() http.Header ResponseWriter() http.ResponseWriter Flush() // contains filtered or unexported methods }
Output is interface for route output handler
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route handles single route
func (*Route) JSON ¶
JSON adds validation for request content so that only requests with content type json is handled
func (*Route) NoCache ¶
NoCache marks request handler output of route will not be cached in any way to client will be sent headers to not cache response
func (*Route) RateLimit ¶
RateLimit sets routes maximum request rate per second from specific remote IP
func (*Route) RateLimitAuth ¶
RateLimitAuth sets routes maximum request rate per time for authorized users
type Router ¶
type Router interface { Get(string, RouteFunc) *Route Post(string, RouteFunc) *Route Put(string, RouteFunc) *Route Delete(string, RouteFunc) *Route // main routing function Route(context Context) bool Handle(pattern string, handler http.Handler) }
Router is interface for implement specific routing engines, for example we have module user which handles users, we can then port module across other projects that uses core