Documentation ¶
Overview ¶
Package web is a lightweight web framework for Go. It's ideal for writing simple, performant backend web services.
Index ¶
- Variables
- func NewCookie(name string, value string, age int64) *http.Cookie
- func Slug(s string, sep string) string
- func Urlencode(data map[string]string) string
- type Context
- func (ctx *Context) Abort(status int, body string)
- func (ctx *Context) BadRequest()
- func (ctx *Context) ContentType(val string) string
- func (ctx *Context) Forbidden()
- func (ctx *Context) GetBasicAuth() (string, string, error)
- func (ctx *Context) GetSecureCookie(name string) (string, bool)
- func (ctx *Context) NotFound(message string)
- func (ctx *Context) NotModified()
- func (ctx *Context) Redirect(status int, url_ string)
- func (ctx *Context) Reset(req *http.Request, s *Server, w http.ResponseWriter)
- func (ctx *Context) SetCookie(cookie *http.Cookie)
- func (ctx *Context) SetHeader(hdr string, val string, unique bool)
- func (ctx *Context) SetSecureCookie(name string, val string, age int64) error
- func (ctx *Context) Unauthorized()
- func (ctx *Context) WriteString(content string)
- type Server
- func (s *Server) Delete(route string, handler interface{})
- func (s *Server) Get(route string, handler interface{})
- func (s *Server) Handle(route string, method string, httpHandler http.Handler)
- func (s *Server) Head(route string, handler interface{})
- func (s *Server) Match(method string, route string, handler interface{})
- func (s *Server) Post(route string, handler interface{})
- func (s *Server) Process(c http.ResponseWriter, req *http.Request)
- func (s *Server) Put(route string, handler interface{})
- func (s *Server) ServeHTTP(c http.ResponseWriter, req *http.Request)
- func (s *Server) SetLogger(logger *log.Logger)
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingCookieSecret = errors.New("Secret Key for secure cookies has not been set. Assign one to web.Config.CookieSecret.") ErrInvalidKey = errors.New("The keys for secure cookies have not been initialized. Ensure that a Run* method is being called") )
var Config = &ServerConfig{ RecoverPanic: true, ColorOutput: true, }
Config is the configuration of the main server.
var NoValueNeeded = fmt.Errorf("No value needed")
var NotSupported = fmt.Errorf("Type is not supported")
Functions ¶
func NewCookie ¶ added in v0.2.0
NewCookie is a helper method that returns a new http.Cookie object. Duration is specified in seconds. If the duration is zero, the cookie is permanent. This can be used in conjunction with ctx.SetCookie.
Types ¶
type Context ¶
type Context struct { Request *http.Request Params map[string]string Server *Server http.ResponseWriter }
A Context object is created for every incoming HTTP request, and is passed to handlers as an optional first argument. It provides information about the request, including the http.Request object, the GET and POST params, and acts as a Writer for the response.
func (*Context) Abort ¶
Abort is a helper method that sends an HTTP header and an optional body. It is useful for returning 4xx or 5xx errors. Once it has been called, any return value from the handler will not be written to the response.
func (*Context) BadRequest ¶ added in v0.2.0
func (ctx *Context) BadRequest()
BadRequest writes a 400 HTTP response
func (*Context) ContentType ¶ added in v0.2.0
ContentType sets the Content-Type header for an HTTP response. For example, ctx.ContentType("json") sets the content-type to "application/json" If the supplied value contains a slash (/) it is set as the Content-Type verbatim. The return value is the content type as it was set, or an empty string if none was found.
func (*Context) Forbidden ¶ added in v0.2.0
func (ctx *Context) Forbidden()
Forbidden writes a 403 HTTP response
func (*Context) GetBasicAuth ¶ added in v0.2.0
GetBasicAuth returns the decoded user and password from the context's 'Authorization' header.
func (*Context) NotModified ¶ added in v0.2.0
func (ctx *Context) NotModified()
Notmodified writes a 304 HTTP response
func (*Context) SetHeader ¶ added in v0.2.0
SetHeader sets a response header. If `unique` is true, the current value of that header will be overwritten . If false, it will be appended.
func (*Context) SetSecureCookie ¶
func (*Context) Unauthorized ¶ added in v0.2.0
func (ctx *Context) Unauthorized()
Unauthorized writes a 401 HTTP response
func (*Context) WriteString ¶
WriteString writes string data into the response object.
type Server ¶ added in v0.2.0
type Server struct { Config *ServerConfig Logger *log.Logger Env map[string]interface{} TypeHandlers []typeHandlerDelegate // contains filtered or unexported fields }
Server represents a web.go server.
func (*Server) Delete ¶ added in v0.2.0
Delete adds a handler for the 'DELETE' http method for server s.
func (*Server) Match ¶ added in v0.2.0
Match adds a handler for an arbitrary http method for server s.
func (*Server) Process ¶ added in v0.2.0
func (s *Server) Process(c http.ResponseWriter, req *http.Request)
Process invokes the routing system for server s