Documentation ¶
Index ¶
- Constants
- Variables
- func Box2Http(b *B) http.Handler
- func GetError(ctx context.Context) error
- func GetRequest(ctx context.Context) *http.Request
- func GetResponse(ctx context.Context) http.ResponseWriter
- func GetUrlParameter(ctx context.Context, param string) string
- func Param(r *http.Request, param string) string
- func SetBoxContext(ctx context.Context, c *C) context.Context
- func SetError(ctx context.Context, err error)
- type A
- func Action(handler interface{}) *A
- func ActionPost(handler interface{}) *A
- func AnyMethod(handler interface{}) *A
- func Connect(handler interface{}) *A
- func Delete(handler interface{}) *A
- func Get(handler interface{}) *A
- func Head(handler interface{}) *A
- func Options(handler interface{}) *A
- func Patch(handler interface{}) *A
- func Post(handler interface{}) *A
- func Put(handler interface{}) *A
- func Trace(handler interface{}) *A
- type Attr
- type B
- type C
- type E
- type H
- type Handler
- type I
- type Interceptor
- type R
- func (r *R) GetActions() []*A
- func (r *R) Group(path string) *R
- func (r *R) Handle(method string, path string, handler interface{}) *A
- func (r *R) HandleFunc(method string, path string, handler http.HandlerFunc) *A
- func (r *R) Match(path string, parameters map[string]string) (result *R)
- func (r *R) Resource(locator string) *R
- func (r *R) Use(interceptor ...I) *R
- func (r *R) WithActions(action ...*A) *R
- func (r *R) WithAttribute(key string, value interface{}) *R
- func (r *R) WithInterceptors(interceptor ...I) *R
Constants ¶
View Source
const ( AttrHttpMethod = "attr_http_method" AttrHttpBind = "attr_http_bind" AttrDoc = "attr_doc" )
View Source
const HttpMethodAny = "*"
Variables ¶
View Source
var ( ErrResourceNotFound = errors.New("resource_not_found") ErrMethodNotAllowed = errors.New("method_not_allowed") )
View Source
var DefaultAccessLogPrintln = log.Println
Functions ¶
func GetResponse ¶
func GetResponse(ctx context.Context) http.ResponseWriter
func GetUrlParameter ¶ added in v0.2.0
Types ¶
type A ¶
type A struct { Attr HttpMethod string // Name is the name to identify the action AND the invocation to url suffix Name string // Bound is true if this action is not an extended action Bound bool // Interceptors is the list of actions that will be executed before executing handler Interceptors []I // contains filtered or unexported fields }
An A stands for Action
func ActionPost ¶
func ActionPost(handler interface{}) *A
func (*A) GetHandler ¶ added in v0.3.1
GetHandler overwrite default action name
func (*A) WithAttribute ¶
func (*A) WithInterceptors ¶
type Attr ¶
type Attr map[string]interface{}
func (Attr) GetAttribute ¶
Get Attribute value using key string from Box, Resource or Action.
func (Attr) SetAttribute ¶
Set Attribute key-value to Box, Resource or Action.
type B ¶
func (*B) ListenAndServe ¶ added in v0.1.4
ListenAndServe is a helper that creates a new http.Server and call to its method ListenAndServe on address :8080
type C ¶
type C struct { Resource *R Action *A Parameters map[string]string // TODO: add headers // TODO: add query // TODO: add box // TODO: ¿add marshaler and unmarshaler? Request *http.Request Response http.ResponseWriter // contains filtered or unexported fields }
An C is a box context to store box related thing in context such as *R, *A, *E, etc
func GetBoxContext ¶ added in v0.2.0
type H ¶
An H stands for Handler
func PrettyError ¶ added in v0.3.0
func RecoverFromPanic ¶ added in v0.3.0
RecoverFromPanic is an interceptor to recover and pretty print a stacktrace
type Interceptor ¶ added in v0.4.2
type Interceptor = I // Just alias to make it more readable
type R ¶
type R struct { Attr // Path is a literal or placeholder that matches with a portion of the path Path string // Parent is a reference to parent resource Parent *R // Children is the list of descendent resources Children []*R // Interceptors is the list of actions that will be executed before each // action or resource under this resource Interceptors []I // contains filtered or unexported fields }
R stands for Resource
func NewResource ¶
func NewResource() *R
func (*R) GetActions ¶ added in v0.1.0
GetActions retrieve the slice of actions defined in this resource
func (*R) HandleFunc ¶ added in v0.2.1
func (*R) WithAttribute ¶
func (*R) WithInterceptors ¶
Add interceptor to this resource
Source Files ¶
Click to show internal directories.
Click to hide internal directories.