box

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2020 License: MIT Imports: 12 Imported by: 8

Documentation

Index

Constants

View Source
const (
	AttrHttpMethod = "attr_http_method"
	AttrHttpBind   = "attr_http_bind"
	AttrDoc        = "attr_doc"
)

Variables

This section is empty.

Functions

func Box2Http

func Box2Http(b *B) http.Handler

func GetError

func GetError(ctx context.Context) error

func GetRequest

func GetRequest(ctx context.Context) *http.Request

func GetResponse

func GetResponse(ctx context.Context) http.ResponseWriter

func SetError

func SetError(ctx context.Context, err error)

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 Action

func Action(handler interface{}) *A

func ActionPost

func ActionPost(handler interface{}) *A

func Connect

func Connect(handler interface{}) *A

func Delete

func Delete(handler interface{}) *A

func Get

func Get(handler interface{}) *A

Bind shortcuts:

func Head(handler interface{}) *A

func Options

func Options(handler interface{}) *A

func Patch

func Patch(handler interface{}) *A

func Post

func Post(handler interface{}) *A

func Put

func Put(handler interface{}) *A

func Trace

func Trace(handler interface{}) *A

func (*A) Bind

func (a *A) Bind(method string) *A

func (*A) WithAttribute

func (a *A) WithAttribute(key string, value interface{}) *A

func (*A) WithInterceptors

func (a *A) WithInterceptors(interceptor ...I) *A

func (*A) WithName

func (a *A) WithName(name string) *A

WithName overwrite default action name

type Attr

type Attr map[string]interface{}

func (Attr) GetAttribute

func (a Attr) GetAttribute(key string) (value interface{})

Get Attribute value using key string from Box, Resource or Action.

func (Attr) SetAttribute

func (a Attr) SetAttribute(key string, value interface{})

Set Attribute key-value to Box, Resource or Action.

type B

type B struct {
	// R is the root resource in box
	*R
}

func NewBox

func NewBox() *B

func (*B) Serve

func (b *B) Serve()

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

type E

type E interface {
	error
}

An E is a box error :D

type H

type H func(ctx context.Context)

An H stands for Handler

func InterceptorPrintError

func InterceptorPrintError(next H) H

type I

type I func(next H) H

An I stands for Interceptor

type R

type R struct {
	Attr

	// Path is a literal or placehoder that matches with a portion of the path
	Path string

	// Parent is a reference to parent resource
	Parent *R

	// Children is the list of desdendent 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

func (r *R) GetActions() []*A

GetActions retrieve the slice of actions defined in this resource

func (*R) Match

func (r *R) Match(path string, parameters map[string]string) (result *R)

TODO: maybe parameters should be a type `P`

func (*R) Resource

func (r *R) Resource(locator string) *R

Resource defines a new resource below current resource

func (*R) WithActions

func (r *R) WithActions(action ...*A) *R

Add action to this resource

func (*R) WithAttribute

func (r *R) WithAttribute(key string, value interface{}) *R

func (*R) WithInterceptors

func (r *R) WithInterceptors(interceptor ...I) *R

Add interceptor to this resource

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL