mirango

package module
v0.0.0-...-0a3ae0d Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2017 License: MIT Imports: 11 Imported by: 0

README

Build Status GoDoc

Documentation

Overview

Mirango is a conveniently smart web framework that is built with reusibility and easiness in mind.

Mirango supports the following handler types:

mirango.Handler
mirango.HandlerFunc
func(*Context) interface{}
func(*Context)
framework.Handler
framework.HandlerFunc
func(framework.Context) interface{}
func(framework.Context)
func(*Response, *Request) interface{}
func(*Response, *Request)
func(framework.Response, framework.Request) interface{}
func(framework.Response, framework.Request)
http.Handler
http.HandlerFunc
func(http.ResponseWriter, *http.Request) interface{}
func(http.ResponseWriter, *http.Request)

Index

Constants

View Source
const (
	IN_PATH paramIn = iota
	IN_QUERY
	IN_HEADER
	IN_BODY
)

Variables

This section is empty.

Functions

func With

func With(mw ...interface{}) middleware

func WriteAsJson

func WriteAsJson(w http.ResponseWriter, status int, value interface{}) (int, error)

func WriteAsXml

func WriteAsXml(w http.ResponseWriter, status int, value interface{}, writeHeader bool) (int, error)

func WriteEntity

func WriteEntity(w http.ResponseWriter, status int, value interface{}, encoding string) (int, error)

func WriteJson

func WriteJson(w http.ResponseWriter, status int, value interface{}, contentType string) (int, error)

func WriteString

func WriteString(w http.ResponseWriter, status int, str string) (int, error)

Types

type CaseSensitive

type CaseSensitive string

type Context

type Context struct {
	framework.LogWriter
	*Response
	*Request
	// contains filtered or unexported fields
}

func NewContext

func NewContext(res *Response, req *Request) *Context

func (*Context) End

func (c *Context) End()

func (*Context) GetValue

func (c *Context) GetValue(k interface{}) framework.Value

func (*Context) Header

func (c *Context) Header() http.Header

func (*Context) ID

func (c *Context) ID() int64

func (*Context) Locale

func (c *Context) Locale() framework.Locale

func (*Context) Operation

func (c *Context) Operation() framework.Operation

func (*Context) SetValue

func (c *Context) SetValue(k interface{}, v interface{})

func (*Context) User

func (c *Context) User() framework.User

func (*Context) Value

func (c *Context) Value(k interface{}) interface{}

func (*Context) Values

func (c *Context) Values() framework.Values

type Handler

type Handler interface {
	ServeHTTP(*Context) interface{}
}

type HandlerFunc

type HandlerFunc func(*Context) interface{}

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(c *Context) interface{}

type Middleware

type Middleware interface {
	Run(Handler) Handler
}

func CheckAccepts

func CheckAccepts(o *Operation) Middleware

func CheckParams

func CheckParams(o *Operation) Middleware

func CheckReturns

func CheckReturns(o *Operation) Middleware

func CheckSchemes

func CheckSchemes(o *Operation) Middleware

func MiddlewareFunc

func MiddlewareFunc(f func(Handler) Handler) Middleware

type Mirango

type Mirango struct {
	*Route
	// contains filtered or unexported fields
}

func New

func New(path interface{}) *Mirango

func (*Mirango) Codecs

func (m *Mirango) Codecs(c ...framework.Codec)

func (*Mirango) Decoders

func (m *Mirango) Decoders(d ...framework.Decoder)

func (*Mirango) Encoders

func (m *Mirango) Encoders(e ...framework.Encoder)

func (*Mirango) Logger

func (m *Mirango) Logger(l framework.Logger)

func (*Mirango) Params

func (m *Mirango) Params(params ...*Param) *Mirango

func (*Mirango) Prepare

func (m *Mirango) Prepare()

func (*Mirango) ServeHTTP

func (m *Mirango) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Mirango) Server

func (m *Mirango) Server(s framework.Server)

func (*Mirango) SessionStore

func (m *Mirango) SessionStore(ss framework.SessionStore)

func (*Mirango) Start

func (m *Mirango) Start(addr string) error

func (*Mirango) StartTLS

func (m *Mirango) StartTLS(addr string, certFile string, keyFile string) error

func (Mirango) String

func (n Mirango) String() string

type Operation

type Operation struct {
	// contains filtered or unexported fields
}

func DELETE

func DELETE(h interface{}) *Operation

func DELETENested

func DELETENested(h interface{}, cb func(*Operation)) *Operation

func GET

func GET(h interface{}) *Operation

func GETNested

func GETNested(h interface{}, cb func(*Operation)) *Operation

func NewOperation

func NewOperation(h interface{}) *Operation

func PATCH

func PATCH(h interface{}) *Operation

func PATCHNested

func PATCHNested(h interface{}, cb func(*Operation)) *Operation

func POST

func POST(h interface{}) *Operation

func POSTNested

func POSTNested(h interface{}, cb func(*Operation)) *Operation

func PUT

func PUT(h interface{}) *Operation

func PUTNested

func PUTNested(h interface{}, cb func(*Operation)) *Operation

func (*Operation) Accepts

func (o *Operation) Accepts(accepts ...string) *Operation

func (*Operation) AcceptsOnly

func (o *Operation) AcceptsOnly(accepts ...string) *Operation

func (*Operation) Apply

func (o *Operation) Apply(p ...Preset) *Operation

func (*Operation) BodyParam

func (o *Operation) BodyParam(name string) *Param

func (*Operation) BuildPath

func (o *Operation) BuildPath(v ...interface{}) string

func (*Operation) Clone

func (o *Operation) Clone() *Operation

func (*Operation) GetAccepts

func (o *Operation) GetAccepts() []string

func (*Operation) GetFullPath

func (o *Operation) GetFullPath() string

func (*Operation) GetMethods

func (o *Operation) GetMethods() []string

func (*Operation) GetMiddleware

func (o *Operation) GetMiddleware() []Middleware

func (*Operation) GetName

func (o *Operation) GetName() string

func (*Operation) GetParams

func (o *Operation) GetParams() *Params

func (*Operation) GetPath

func (o *Operation) GetPath() string

func (*Operation) GetReturns

func (o *Operation) GetReturns() []string

func (*Operation) GetRoute

func (o *Operation) GetRoute() framework.Route

func (*Operation) GetSchemes

func (o *Operation) GetSchemes() []string

func (*Operation) HeaderParam

func (o *Operation) HeaderParam(name string) *Param

func (*Operation) Methods

func (o *Operation) Methods(methods ...string) *Operation

func (*Operation) Name

func (o *Operation) Name(name string) *Operation

func (*Operation) Params

func (o *Operation) Params(params ...*Param) *Operation

func (*Operation) PathParam

func (o *Operation) PathParam(name string) *Param

func (*Operation) QueryParam

func (o *Operation) QueryParam(name string) *Param

func (*Operation) Returns

func (o *Operation) Returns(returns ...string) *Operation

func (*Operation) ReturnsOnly

func (o *Operation) ReturnsOnly(returns ...string) *Operation

func (*Operation) Schemes

func (o *Operation) Schemes(schemes ...string) *Operation

func (*Operation) SchemesOnly

func (o *Operation) SchemesOnly(schemes ...string) *Operation

func (*Operation) ServeHTTP

func (o *Operation) ServeHTTP(c *Context) interface{}

func (*Operation) Uses

func (o *Operation) Uses(h interface{}) *Operation

func (*Operation) With

func (o *Operation) With(mw ...interface{}) *Operation

type Operations

type Operations struct {
	// contains filtered or unexported fields
}

func NewOperations

func NewOperations() *Operations

func (*Operations) Append

func (ops *Operations) Append(operations ...*Operation)

func (*Operations) Apply

func (ops *Operations) Apply(p ...Preset)

func (*Operations) Clone

func (ops *Operations) Clone() *Operations

func (*Operations) Get

func (ops *Operations) Get(name string) *Operation

func (*Operations) GetAll

func (ops *Operations) GetAll() []*Operation

func (*Operations) GetByIndex

func (ops *Operations) GetByIndex(i int) *Operation

func (*Operations) GetByMethod

func (ops *Operations) GetByMethod(method string) *Operation

func (*Operations) Len

func (ops *Operations) Len() int

func (*Operations) Set

func (ops *Operations) Set(operations ...*Operation)

func (*Operations) Union

func (ops *Operations) Union(nops *Operations)

type Param

type Param struct {
	// contains filtered or unexported fields
}

Param

func BodyParam

func BodyParam(name string) *Param

func HeaderParam

func HeaderParam(name string) *Param

func NewParam

func NewParam(name string) *Param

func PathParam

func PathParam(name string) *Param

func QueryParam

func QueryParam(name string) *Param

func (*Param) As

func (p *Param) As(as framework.ValueType) *Param

func (*Param) Clone

func (p *Param) Clone() *Param

func (*Param) File

func (p *Param) File() *Param

func (*Param) GetAs

func (p *Param) GetAs() framework.ValueType

func (*Param) GetName

func (p *Param) GetName() string

func (*Param) In

func (p *Param) In(in ...paramIn) *Param

If a Param is in path then it is required.

func (*Param) IsFile

func (p *Param) IsFile() bool

func (*Param) IsIn

func (p *Param) IsIn(in ...paramIn) bool

If a Param is in path then it is required.

func (*Param) IsMultiple

func (p *Param) IsMultiple() bool

func (*Param) IsRequired

func (p *Param) IsRequired() bool

func (*Param) Multiple

func (p *Param) Multiple() *Param

func (*Param) Name

func (p *Param) Name(name string) *Param

func (*Param) Required

func (p *Param) Required() *Param

func (*Param) Validate

Validate returns the first error it encountered

func (*Param) ValidateAll

func (p *Param) ValidateAll(c framework.Context, v framework.ParamValue) *validation.Error

ValidateAll returns all the errors it encountered

func (*Param) Validators

func (p *Param) Validators(validators ...validation.Validator) *Param

Must sets the validators to use.

type Params

type Params struct {
	// contains filtered or unexported fields
}

func NewParams

func NewParams() *Params

func (*Params) Append

func (p *Params) Append(params ...*Param)

func (*Params) Clone

func (p *Params) Clone() *Params

func (*Params) ContainsBodyParams

func (p *Params) ContainsBodyParams() bool

func (*Params) ContainsFiles

func (p *Params) ContainsFiles() bool

func (*Params) Get

func (p *Params) Get(name string) *Param

func (*Params) GetAll

func (p *Params) GetAll() map[string]*Param

func (*Params) Len

func (p *Params) Len() int

func (*Params) Set

func (p *Params) Set(params ...*Param)

func (*Params) Union

func (p *Params) Union(params *Params)

func (*Params) Validate

Validate returns the first error it encountered

func (*Params) ValidateAll

func (pa *Params) ValidateAll(c framework.Context, vs framework.ParamValues) *validation.Error

ValidateAll returns all the errors it encountered for each param

func (*Params) ValidateFirst

func (pa *Params) ValidateFirst(c framework.Context, vs framework.ParamValues) *validation.Error

ValidateFirst returns the first error it encountered for each param

type Preset

type Preset interface {
	ApplyTo(*Operation)
}

type PresetFunc

type PresetFunc func(*Operation)

func (PresetFunc) ApplyTo

func (f PresetFunc) ApplyTo(o *Operation)

type Presets

type Presets []Preset

func Apply

func Apply(p ...Preset) Presets

func (Presets) To

func (p Presets) To(operations ...*Operation)

func (Presets) Union

func (p Presets) Union(o Presets)

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(r *http.Request) *Request

func (*Request) GetSessionValue

func (r *Request) GetSessionValue(string, interface{}) (framework.Value, error)

func (*Request) IsSet

func (r *Request) IsSet(name string) bool

ParamOk returns the input parameter value by its name.

func (*Request) Method

func (r *Request) Method() string

func (*Request) Param

func (r *Request) Param(name string) framework.ParamValue

Param returns the input parameter value by its name.

func (*Request) Params

func (r *Request) Params(names ...string) framework.ParamValues

func (*Request) Path

func (r *Request) Path() string

func (*Request) Session

func (r *Request) Session(name string) framework.Session

func (*Request) Sessions

func (r *Request) Sessions() framework.Sessions

func (*Request) SetSessionValue

func (r *Request) SetSessionValue(string, interface{}, interface{}) error

type Resource

type Resource struct {
	Name        string
	Route       *Route
	EntityRoute *Route
	Index       *Operation
	Create      *Operation
	Get         *Operation
	Update      *Operation
	Patch       *Operation
	Delete      *Operation
	// contains filtered or unexported fields
}

func NewResource

func NewResource(name string, re interface{}) *Resource

func NewResourceNested

func NewResourceNested(name string, re interface{}, cb func(*Resource)) *Resource

func (*Resource) AddResource

func (r *Resource) AddResource(resource *Resource) *Resource

func (*Resource) AddResourceNested

func (r *Resource) AddResourceNested(resource *Resource, cb func(*Resource)) *Resource

func (*Resource) Clone

func (r *Resource) Clone() *Resource

func (*Resource) Resource

func (r *Resource) Resource(name string, re interface{}) *Resource

func (*Resource) ResourceNested

func (r *Resource) ResourceNested(name string, re interface{}, cb func(*Resource)) *Resource

type Response

type Response struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(w http.ResponseWriter, encoders framework.Encoders) *Response

func (*Response) CloseNotify

func (w *Response) CloseNotify() <-chan bool

func (*Response) ContentLength

func (w *Response) ContentLength() int

func (*Response) Flush

func (w *Response) Flush()

func (*Response) Render

func (w *Response) Render(c *Context, data interface{}) error

func (*Response) StatusCode

func (w *Response) StatusCode() int

func (*Response) Stream

func (w *Response) Stream(status int, d time.Duration, f func(int64) (interface{}, bool)) error

func (*Response) StreamAsJson

func (w *Response) StreamAsJson(status int, d time.Duration, f func(int64) (interface{}, bool)) error

func (*Response) StreamAsXml

func (w *Response) StreamAsXml(status int, d time.Duration, f func(int64) (interface{}, bool)) error

func (*Response) Write

func (w *Response) Write(bytes []byte) (int, error)

func (*Response) WriteAsJson

func (w *Response) WriteAsJson(status int, value interface{}) error

func (*Response) WriteAsXml

func (w *Response) WriteAsXml(status int, value interface{}, writeHeader bool) error

func (*Response) WriteEntity

func (w *Response) WriteEntity(status int, value interface{}) error

func (*Response) WriteHeader

func (w *Response) WriteHeader(httpStatus int)

func (*Response) WriteJson

func (w *Response) WriteJson(status int, value interface{}, contentType string) error

func (*Response) WriteString

func (w *Response) WriteString(status int, str string) error

type Route

type Route struct {
	// contains filtered or unexported fields
}

func NewRoute

func NewRoute(path interface{}) *Route

func NewRouteNested

func NewRouteNested(path interface{}, cb func(*Route)) *Route

func (*Route) Accepts

func (r *Route) Accepts(accepts ...string) *Route

func (*Route) AcceptsOnly

func (r *Route) AcceptsOnly(accepts ...string) *Route

func (*Route) AddResource

func (r *Route) AddResource(resource *Resource) *Resource

func (*Route) AddResourceNested

func (r *Route) AddResourceNested(resource *Resource, cb func(*Resource)) *Resource

func (*Route) AddRoute

func (r *Route) AddRoute(route *Route) *Route

func (*Route) AddRouteNested

func (r *Route) AddRouteNested(route *Route, cb func(*Route)) *Route

func (*Route) Apply

func (r *Route) Apply(p ...Preset)

func (*Route) BodyParam

func (r *Route) BodyParam(name string) *Param

func (*Route) Branch

func (r *Route) Branch(path interface{}) *Route

func (*Route) BranchNested

func (r *Route) BranchNested(path interface{}, cb func(*Route)) *Route

func (*Route) BuildPath

func (r *Route) BuildPath(v ...interface{}) string

func (*Route) Clone

func (r *Route) Clone() *Route

func (*Route) DELETE

func (r *Route) DELETE(h interface{}) *Operation

func (*Route) DELETENested

func (r *Route) DELETENested(h interface{}, cb func(*Operation)) *Operation

func (*Route) GET

func (r *Route) GET(h interface{}) *Operation

func (*Route) GETNested

func (r *Route) GETNested(h interface{}, cb func(*Operation)) *Operation

func (*Route) GetAccepts

func (r *Route) GetAccepts() []string

func (*Route) GetFullPath

func (r *Route) GetFullPath() string

func (*Route) GetMethodNotAllowedHandler

func (r *Route) GetMethodNotAllowedHandler() Handler

func (*Route) GetMiddleware

func (r *Route) GetMiddleware() []Middleware

func (*Route) GetNotFoundHandler

func (r *Route) GetNotFoundHandler() Handler

func (*Route) GetOperations

func (r *Route) GetOperations() *Operations

func (*Route) GetPanicHandler

func (r *Route) GetPanicHandler() Handler

func (*Route) GetParams

func (r *Route) GetParams() *Params

func (*Route) GetPath

func (r *Route) GetPath() string

func (*Route) GetReturns

func (r *Route) GetReturns() []string

func (*Route) GetSchemes

func (r *Route) GetSchemes() []string

func (*Route) HeaderParam

func (r *Route) HeaderParam(name string) *Param

func (*Route) MethodNotAllowedHandler

func (r *Route) MethodNotAllowedHandler(h interface{}) *Route

func (*Route) NotFoundHandler

func (r *Route) NotFoundHandler(h interface{}) *Route

func (*Route) Operations

func (r *Route) Operations(ops ...*Operation) *Route

func (*Route) PATCH

func (r *Route) PATCH(h interface{}) *Operation

func (*Route) PATCHNested

func (r *Route) PATCHNested(h interface{}, cb func(*Operation)) *Operation

func (*Route) POST

func (r *Route) POST(h interface{}) *Operation

func (*Route) POSTNested

func (r *Route) POSTNested(h interface{}, cb func(*Operation)) *Operation

func (*Route) PUT

func (r *Route) PUT(h interface{}) *Operation

func (*Route) PUTNested

func (r *Route) PUTNested(h interface{}, cb func(*Operation)) *Operation

func (*Route) PanicHandler

func (r *Route) PanicHandler(h interface{}) *Route

func (*Route) Params

func (r *Route) Params(params ...*Param) *Route

func (*Route) PathParam

func (r *Route) PathParam(name string) *Param

func (*Route) QueryParam

func (r *Route) QueryParam(name string) *Param

func (*Route) Resource

func (r *Route) Resource(name string, re interface{}) *Resource

func (*Route) ResourceNested

func (r *Route) ResourceNested(name string, re interface{}, cb func(*Resource)) *Resource

func (*Route) Returns

func (r *Route) Returns(returns ...string) *Route

func (*Route) ReturnsOnly

func (r *Route) ReturnsOnly(returns ...string) *Route

func (*Route) Schemes

func (r *Route) Schemes(schemes ...string) *Route

func (*Route) SchemesOnly

func (r *Route) SchemesOnly(schemes ...string) *Route

func (*Route) ServeHTTP

func (r *Route) ServeHTTP(c *Context, res result) interface{}

func (*Route) With

func (r *Route) With(mw ...interface{}) *Route

type Server

type Server struct {
	*http.Server
	Logger framework.LogWriter
}

func DefaultServer

func DefaultServer() *Server

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error

func (*Server) SetAddr

func (srv *Server) SetAddr(addr string)

func (*Server) SetHandler

func (srv *Server) SetHandler(h http.Handler)

func (*Server) SetLogger

func (srv *Server) SetLogger(logger framework.LogWriter)

Jump to

Keyboard shortcuts

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