Documentation
¶
Index ¶
- Constants
- Variables
- func JSONResponse(w http.ResponseWriter, data interface{})
- func JSONResponseVerbose(w http.ResponseWriter, status int, header http.Header, data interface{})
- func Params(req *http.Request) []string
- type Compiler
- type Context
- func (c *Context) DecodeJSON(data interface{}) error
- func (c *Context) DecodeRequest() error
- func (c *Context) Init(w http.ResponseWriter, r *http.Request)
- func (c *Context) JSON(data interface{})
- func (c *Context) Redirect(urlStr string, code int)
- func (c *Context) Status(status int)
- func (c *Context) StatusError(status int, errorDescription string)
- func (c *Context) StatusText(status int)
- func (c *Context) Text(data string)
- type ContextInterface
- type Error
- type Handler
- type InvalidTemplateError
- type OpCode
- type Pattern
- type Router
- func (r *Router) All(path string, controller interface{})
- func (r *Router) Delete(path string, controller interface{})
- func (r *Router) Get(path string, controller interface{})
- func (s *Router) Handle(method, path string, v interface{}) error
- func (r *Router) Head(path string, controller interface{})
- func (s *Router) Match(method string, path string) (h Handler, pathParams map[string]string, paramsList []string, err error)
- func (r *Router) Options(path string, controller interface{})
- func (r *Router) Patch(path string, controller interface{})
- func (r *Router) Post(path string, controller interface{})
- func (r *Router) Put(path string, controller interface{})
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type Template
Constants ¶
const ( // OpNop does nothing OpNop = OpCode(iota) // OpPush pushes a component to stack OpPush // OpLitPush pushes a component to stack if it matches to the literal OpLitPush // OpPushM concatenates the remaining components and pushes it to stack OpPushM // OpConcatN pops N items from stack, concatenates them and pushes it back to stack OpConcatN // OpCapture pops an item and binds it to the variable OpCapture // OpEnd is the least positive invalid opcode. OpEnd )
These constants are the valid values of OpCode.
Variables ¶
var ( // ErrNotMatch indicates that the given HTTP request path does not match to the pattern. ErrNotMatch = errors.New("not match to the path pattern") // ErrInvalidPattern indicates that the given definition of Pattern is not valid. ErrInvalidPattern = errors.New("invalid pattern") )
Functions ¶
func JSONResponse ¶
func JSONResponse(w http.ResponseWriter, data interface{})
JSONResponse response json to any http writer if data is a error it will response a errror json
func JSONResponseVerbose ¶
func JSONResponseVerbose(w http.ResponseWriter, status int, header http.Header, data interface{})
JSONResponseVerbose response json to any http writer, include status ,header, data
Types ¶
type Compiler ¶
type Compiler interface {
Compile() Template
}
Compiler compiles utilities representation of path templates into marshallable operations. They can be unmarshalled by runtime.NewPattern.
type Context ¶
type Context struct { Writer http.ResponseWriter Request *http.Request Data interface{} }
Context the context of http you can use by startContext, nextContext, procContext, endContext ....
func (*Context) DecodeJSON ¶
DecodeJSON decode json
func (*Context) DecodeRequest ¶
DecodeRequest You can implement your DecodeRequest, it can be form or something else
func (*Context) Init ¶
func (c *Context) Init(w http.ResponseWriter, r *http.Request)
Init the start of context you can define you own link (c *context){c.Context.Init(w,r), your code ...}
func (*Context) StatusError ¶
StatusError output standard error json body by http.Status code exp: StatusError(404,"not fond something"),will response {"error":"not_found", "error_description":"not fond something"}
func (*Context) StatusText ¶
StatusText response textplain by http.Status code
type ContextInterface ¶
type ContextInterface interface { Init(http.ResponseWriter, *http.Request) DecodeRequest() error }
ContextInterface the interface of any context the context must have Init and DecodeRequest
type Handler ¶
type Handler struct { Pat Pattern V interface{} // contains filtered or unexported fields }
Handler the handler instance in router
type InvalidTemplateError ¶
type InvalidTemplateError struct {
// contains filtered or unexported fields
}
InvalidTemplateError indicates that the path template is not valid.
func (InvalidTemplateError) Error ¶
func (e InvalidTemplateError) Error() string
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern is a template pattern of http request paths defined in github.com/googleapis/googleapis/google/api/http.proto.
func MustPattern ¶
MustPattern is a helper function which makes it easier to call NewPattern in variable initialization.
func NewPattern ¶
NewPattern returns a new Pattern from the given definition values. "ops" is a sequence of op codes. "pool" is a constant pool. "verb" is the verb part of the pattern. It is empty if the pattern does not have the part. "version" must be 1 for now. It returns an error if the given definition is invalid.
func ParsePatternURL ¶
ParsePatternURL parse any path to google pattern
func (Pattern) Match ¶
Match examines components if it matches to the Pattern. If it matches, the function returns a mapping from field paths to their captured values. If otherwise, the function returns an error.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router the router
func (*Router) Match ¶
func (s *Router) Match(method string, path string) (h Handler, pathParams map[string]string, paramsList []string, err error)
Match dispatches the request to the first handler whose pattern matches to r.Method and r.Path.
type Template ¶
type Template struct { // OpCodes is a sequence of operations. OpCodes []int // Pool is a constant pool Pool []string // Verb is a VERB part in the template. Verb string // Fields is a list of field paths bound in this template. Fields []string // Original template (example: /v1/a_bit_of_everything) Template string }
Template is a compiled representation of path templates.