Documentation ¶
Index ¶
- Constants
- Variables
- func Dir(root string, listDirectory bool) http.FileSystem
- func IsDebugging() bool
- func SetMode(value string)
- func StripPrefixFallback(prefix string, fs http.FileSystem, listDirectory bool, fallback string) http.Handler
- type Context
- func (c *Context) AbortRender(code int, request string, err interface{})
- func (c *Context) AbortWithStatus(code int)
- func (c *Context) ClientIP() string
- func (c *Context) ContentType() string
- func (c *Context) Cookie(name string) (string, error)
- func (c *Context) Data(code int, contentType string, data []byte)
- func (c *Context) ErrorHTML(code int, title, content string)
- func (c *Context) File(filepath string)
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) GetBool(key string) (b bool)
- func (c *Context) GetDuration(key string) (d time.Duration)
- func (c *Context) GetFloat64(key string) (f64 float64)
- func (c *Context) GetHeader(key string) string
- func (c *Context) GetInt(key string) (i int)
- func (c *Context) GetInt64(key string) (i64 int64)
- func (c *Context) GetString(key string) (s string)
- func (c *Context) GetStringMap(key string) (sm map[string]interface{})
- func (c *Context) GetStringMapString(key string) (sms map[string]string)
- func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
- func (c *Context) GetStringSlice(key string) (ss []string)
- func (c *Context) GetTime(key string) (t time.Time)
- func (c *Context) HTML(code int, name string, obj interface{})
- func (c *Context) HTMLString(name string, obj interface{}) string
- func (c *Context) Header(key, value string)
- func (c *Context) IndentedJSON(code int, obj interface{})
- func (c *Context) JSON(code int, obj interface{})
- func (c *Context) LayoutHTML(code int, layout, name string, obj interface{})
- func (c *Context) MustGet(key string) interface{}
- func (c *Context) Param(key string) (string, bool)
- func (c *Context) Redirect(code int, location string)
- func (c *Context) Render(code int, r render.Render)
- func (c *Context) Set(key string, value interface{})
- func (c *Context) SetCookie(name string, value string, maxAge int, path string, domain string, secure bool, ...)
- func (c *Context) Static(relativePath, prefix string, listDirectory bool, fallback ...string)
- func (c *Context) Status(code int)
- func (c *Context) Stream(step func(w io.Writer) bool)
- func (c *Context) String(code int, format string, values ...interface{})
- func (c *Context) XML(code int, obj interface{})
- type Engine
- func (engine *Engine) LoadHTMLGlob(pattern string)
- func (e *Engine) Run(addr ...string) (server *http.Server, err error)
- func (e *Engine) RunTLS(addr string, certFile string, keyFile string) (server *http.Server, err error)
- func (e *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (e *Engine) Server(addr ...string) (server *http.Server)
- func (e *Engine) ServerKeepAlive(addr ...string) (server *http.Server)
- func (engine *Engine) SetFuncMap(funcMap template.FuncMap)
- func (engine *Engine) SetHTMLTemplate(templ *template.Template)
- type H
- type Handler
- func Favicon(relativePath string) Handler
- func File(relativePath string) Handler
- func Logger() Handler
- func LoggerWithWriter(out io.Writer) Handler
- func Recovery() Handler
- func RecoveryRender(out io.Writer) Handler
- func RecoveryWithWriter(out io.Writer) Handler
- func Static(relativePath string, listDirectory bool, fallback ...string) Handler
- type HandlerCompose
- type HandlerFinal
- type HandlerRoute
- type Next
- type Param
- type Params
- type ResponseWriter
- type Router
- func (r *Router) ANY(handler Handler) *Router
- func (r *Router) CONNECT(handler HandlerFinal) *Router
- func (r *Router) DELETE(handler HandlerFinal) *Router
- func (r *Router) GET(handler HandlerFinal) *Router
- func (r *Router) HEAD(handler HandlerFinal) *Router
- func (r *Router) Handle(httpMethod string, handler HandlerFinal) *Router
- func (r *Router) OPTIONS(handler HandlerFinal) *Router
- func (r *Router) PATCH(handler HandlerFinal) *Router
- func (r *Router) POST(handler HandlerFinal) *Router
- func (r *Router) PUT(handler HandlerFinal) *Router
- func (r *Router) Route(relativePath string, handles ...HandlerRoute) *Router
- func (r *Router) TRACE(handler HandlerFinal) *Router
- func (r *Router) Use(relativePath string, handles ...Handler) *Router
Constants ¶
const ( DebugMode string = "debug" ReleaseMode string = "release" )
const ENV_CART_MODE = "CART_MODE"
const Version = "v1.0.8"
Variables ¶
var DefaultErrorWriter io.Writer = os.Stderr
var DefaultWriter io.Writer = os.Stdout
Functions ¶
func Dir ¶
func Dir(root string, listDirectory bool) http.FileSystem
Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally in router.Static(). if listDirectory == true, then it works the same as http.Dir() otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.
func IsDebugging ¶
func IsDebugging() bool
IsDebugging returns true if the framework is running in debug mode. Use SetMode(cart.Release) to switch to disable the debug mode.
func StripPrefixFallback ¶ added in v1.0.16
Types ¶
type Context ¶
type Context struct { Request *http.Request Response ResponseWriter Router *Router Params *Params Keys map[string]interface{} // contains filtered or unexported fields }
func (*Context) AbortRender ¶
func (*Context) AbortWithStatus ¶
AbortWithStatus calls `Abort()` and writes the headers with the specified status code. For example, a failed attempt to authenticate a request could use: context.AbortWithStatus(401).
func (*Context) ClientIP ¶
ClientIP implements the best effort algorithm to return the real client IP, it parses X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy. Use X-Forwarded-For before X-Real-Ip as nginx uses X-Real-Ip with the proxy's IP.
func (*Context) ContentType ¶
ContentType returns the Content-Type header of the request.
func (*Context) Get ¶
Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)
func (*Context) GetDuration ¶
GetDuration returns the value associated with the key as a duration.
func (*Context) GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64.
func (*Context) GetStringMap ¶
GetStringMap returns the value associated with the key as a map of interfaces.
func (*Context) GetStringMapString ¶
GetStringMapString returns the value associated with the key as a map of strings.
func (*Context) GetStringMapStringSlice ¶
GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
func (*Context) GetStringSlice ¶
GetStringSlice returns the value associated with the key as a slice of strings.
func (*Context) HTML ¶
HTML renders the HTTP template specified by its file name. It also updates the HTTP code and sets the Content-Type as "text/html". See http://golang.org/doc/articles/wiki/
func (*Context) HTMLString ¶
HTMLString render Template to String
func (*Context) IndentedJSON ¶
IndentedJSON serializes the given struct as pretty JSON (indented + endlines) into the response body. It also sets the Content-Type as "application/json". WARNING: we recommend to use this only for development purposes since printing pretty JSON is more CPU and bandwidth consuming. Use Context.JSON() instead.
func (*Context) JSON ¶
JSON serializes the given struct as JSON into the response body. It also sets the Content-Type as "application/json".
func (*Context) LayoutHTML ¶
LayoutHTML render layout html
func (*Context) MustGet ¶
MustGet returns the value for the given key if it exists, otherwise it panics.
func (*Context) Set ¶
Set is used to store a new key/value pair exclusively for this context. It also lazy initializes c.Keys if it was not used previously.
type Engine ¶
type Engine struct { Router NotFound HandlerFinal FuncMap template.FuncMap Template *template.Template ForwardedByClientIP bool AppEngine bool // contains filtered or unexported fields }
func (*Engine) LoadHTMLGlob ¶
func (*Engine) RunTLS ¶
func (e *Engine) RunTLS(addr string, certFile string, keyFile string) (server *http.Server, err error)
RunTLS
func (*Engine) ServerKeepAlive ¶
func (*Engine) SetFuncMap ¶
func (*Engine) SetHTMLTemplate ¶
type H ¶
type H map[string]interface{}
func (H) MarshalXML ¶
MarshalXML allows type H to be used with xml.Marshal
type Handler ¶
normal handler
func LoggerWithWriter ¶
func Recovery ¶
func Recovery() Handler
Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.
func RecoveryRender ¶
func RecoveryWithWriter ¶
type HandlerCompose ¶
type HandlerFinal ¶
type HandlerFinal func(*Context)
type HandlerRoute ¶
type HandlerRoute func(*Router)
type ResponseWriter ¶
type Router ¶
func (*Router) CONNECT ¶
func (r *Router) CONNECT(handler HandlerFinal) *Router
func (*Router) DELETE ¶
func (r *Router) DELETE(handler HandlerFinal) *Router
func (*Router) GET ¶
func (r *Router) GET(handler HandlerFinal) *Router
func (*Router) HEAD ¶
func (r *Router) HEAD(handler HandlerFinal) *Router
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(handler HandlerFinal) *Router
func (*Router) PATCH ¶
func (r *Router) PATCH(handler HandlerFinal) *Router
func (*Router) POST ¶
func (r *Router) POST(handler HandlerFinal) *Router
func (*Router) PUT ¶
func (r *Router) PUT(handler HandlerFinal) *Router
func (*Router) TRACE ¶
func (r *Router) TRACE(handler HandlerFinal) *Router