Documentation ¶
Overview ¶
fork from martini
fork from martini's router.go
Index ¶
- Constants
- func AuthBasic(user, pass string, r *http.Request) bool
- func AuthClient(allows []string, r *http.Request) (auth bool)
- func AuthFailed(w http.ResponseWriter)
- func AuthSecureURI(user, pass, key string, r *http.Request) bool
- func AuthXAPIKEY(key string, r *http.Request) bool
- func GetValues(requestURI string) (values map[string]string, err error)
- func Md5(key string) string
- func NewContext(options ...CtxOptions) martini.Handler
- func Run(addr string, m http.Handler, ssl ...string) error
- func StructToString(data interface{}) string
- type Context
- func (c *Context) AuthFailed()
- func (c *Context) Data(status int, v []byte)
- func (c *Context) DelData(key string)
- func (c *Context) GetData(key string) (interface{}, bool)
- func (c *Context) JSON(status int, v interface{})
- func (c *Context) NotFound()
- func (c *Context) Params() (params Params)
- func (c *Context) Request(body interface{}) (req *Request, err error)
- func (c *Context) Response(code int, body interface{}, message string, v ...interface{})
- func (c *Context) SetData(key string, value interface{})
- func (c *Context) StaticFile(status int, file string)
- func (c *Context) Text(status int, v string)
- func (c *Context) XML(status int, v interface{})
- type CtxOptions
- type Handler
- type Params
- type Render
- type RenderOpt
- type ReqHeader
- type Request
- type Response
- type ReturnHandler
- type Route
- type RouteMatch
- type Router
- type Routes
- type Server
- func (s *Server) AuthBasic(user, pass string)
- func (s *Server) AuthClient(allows []string)
- func (s *Server) AuthSecureURI(user, pass, key string)
- func (s *Server) AuthXAPIKEY(key string)
- func (s *Server) NotFount()
- func (s *Server) Run(addr string, ssl ...string) error
- func (s *Server) Static(path, uri string)
- func (s *Server) UseRender()
- func (s *Server) UseSession(key string)
- type Session
Constants ¶
const ( ContentType = "Content-Type" ContentLength = "Content-Length" ContentBinary = "application/octet-stream" ContentText = "text/plain; charset=UTF-8" ContentJSON = "application/json; charset=UTF-8" ContentHTML = "text/html; charset=UTF-8" ContentXHTML = "application/xhtml+xml; charset=UTF-8" ContentXML = "text/xml; charset=UTF-8" )
Variables ¶
This section is empty.
Functions ¶
func AuthFailed ¶
func AuthFailed(w http.ResponseWriter)
Types ¶
type Context ¶
type Context struct { martini.Context http.ResponseWriter Req *http.Request // contains filtered or unexported fields }
func (*Context) AuthFailed ¶
func (c *Context) AuthFailed()
AuthFailed write auth failed message to client
func (*Context) NotFound ¶
func (c *Context) NotFound()
NotFound write page not found message to client
func (*Context) Params ¶
Params get all params from router exmaple
s.Get("/user/:id", getUser) func getUser(c *Content) { params := c.Params() id := params["id"] // or id := params.Get("id") // or id := c.Params().Get("id") }
type CtxOptions ¶
type CtxOptions struct { AppName string Version string // Appends the given charset to the Content-Type header. Default is "UTF-8". Charset string // Outputs human readable JSON IndentJSON bool // Outputs human readable XML IndentXML bool // Prefixes the JSON output with the given bytes. PrefixJSON []byte // Prefixes the XML output with the given bytes. PrefixXML []byte // Allows changing of output to XHTML instead of HTML. Default is "text/html" HTMLContentType string }
type context struct { inject.Injector handlers []Handler action Handler rw ResponseWriter index int }
type Handler ¶
type Handler interface{}
Handler can be any callable function. Martini attempts to inject services into the handler's argument list. Martini will panic if an argument could not be fullfilled via dependency injection.
type Params ¶
Params is a map of name/value pairs for named routes. An instance of martini.Params is available to be injected into any route handler.
type Request ¶
type Request struct { Header ReqHeader // request header Body interface{} // body }
request
func RequestReader ¶
func RequestReader(input io.ReadCloser, body interface{}) (req *Request, err error)
read request data
type Response ¶
type Response struct { Code int // custom status code Message string // message Body interface{} // body }
response
func ResponseWriter ¶
initial response data code: status code message: response messages body: response body
type ReturnHandler ¶
ReturnHandler is a service that Martini provides that is called when a route handler returns something. The ReturnHandler is responsible for writing to the ResponseWriter based on the values that are passed into this function.
type Route ¶
type Route interface { // URLWith returns a rendering of the Route's url with the given string params. URLWith([]string) string // Name sets a name for the route. Name(string) // GetName returns the name of the route. GetName() string // Pattern returns the pattern of the route. Pattern() string // Method returns the method of the route. Method() string }
Route is an interface representing a Route in Martini's routing layer.
type RouteMatch ¶
type RouteMatch int
const ( NoMatch RouteMatch = iota StarMatch OverloadMatch ExactMatch )
func (RouteMatch) BetterThan ¶
func (r RouteMatch) BetterThan(o RouteMatch) bool
Higher number = better match
type Router ¶
type Router interface { Routes EnableSecure() // Group adds a group where related routes can be added. Group(string, func(Router), ...Handler) // Get adds a route for a HTTP GET request to the specified matching pattern. Get(string, ...Handler) Route // Patch adds a route for a HTTP PATCH request to the specified matching pattern. Patch(string, ...Handler) Route // Post adds a route for a HTTP POST request to the specified matching pattern. Post(string, ...Handler) Route // Put adds a route for a HTTP PUT request to the specified matching pattern. Put(string, ...Handler) Route // Delete adds a route for a HTTP DELETE request to the specified matching pattern. Delete(string, ...Handler) Route // Options adds a route for a HTTP OPTIONS request to the specified matching pattern. Options(string, ...Handler) Route // Head adds a route for a HTTP HEAD request to the specified matching pattern. Head(string, ...Handler) Route // Connect adds a route for a HTTP CONNECT request to the specified matching pattern. Connect(string, ...Handler) Route // Head adds a route for a HTTP TRACE request to the specified matching pattern. Trace(string, ...Handler) Route // Any adds a route for any HTTP method request to the specified matching pattern. Any(string, ...Handler) Route // AddRoute adds a route for a given HTTP method request to the specified matching pattern. AddRoute(string, string, ...Handler) Route // NotFound sets the handlers that are called when a no route matches a request. Throws a basic 404 by default. NotFound(...Handler) // Handle is the entry point for routing. This is used as a martini.Handler Handle(http.ResponseWriter, *http.Request, martini.Context) }
Router is Martini's de-facto routing interface. Supports HTTP verbs, stacked handlers, and dependency injection.
type Routes ¶
type Routes interface { // URLFor returns a rendered URL for the given route. Optional params can be passed to fulfill named parameters in the route. URLFor(name string, params ...interface{}) string // MethodsFor returns an array of methods available for the path MethodsFor(path string) []string // All returns an array with all the routes in the router. All() []Route }
Routes is a helper service for Martini's routing layer.