Documentation ¶
Index ¶
- type CC
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortWithStatus(code int)
- func (c *Context) Bind(obj interface{}) error
- func (c *Context) BindWith(obj interface{}, b binding.Binding) error
- func (c *Context) Bytes(code int, data ...[]byte)
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) GetBool(key string) (b bool)
- func (c *Context) GetFloat64(key string) (f64 float64)
- func (c *Context) GetInt(key string) (i int)
- func (c *Context) GetInt64(key string) (i64 int64)
- func (c *Context) GetString(key string) (s string)
- func (c *Context) GetUint(key string) (ui uint)
- func (c *Context) GetUint64(key string) (ui64 uint64)
- func (c *Context) IsAborted() bool
- func (c *Context) JSON(data interface{}, err error)
- func (c *Context) JSONMap(data map[string]interface{}, err error)
- func (c *Context) Next()
- func (c *Context) Protobuf(data proto.Message, err error)
- func (c *Context) Render(code int, r render.Render)
- func (c *Context) Set(key string, value interface{})
- func (c *Context) Status(code int)
- func (c *Context) String(code int, format string, values ...interface{})
- func (c *Context) XML(data interface{}, err error)
- type Engine
- func (engine *Engine) InitMethod(handler ...HandlerFunc)
- func (engine *Engine) Inject(pattern string, handlers ...HandlerFunc)
- func (engine *Engine) NoMethod(handlers ...HandlerFunc)
- func (engine *Engine) NoRoute(handlers ...HandlerFunc)
- func (engine *Engine) Run() (err error)
- func (engine *Engine) RunServer(chaincode cc.Chaincode) (err error)
- func (engine *Engine) Serve(stub cc.ChaincodeStubInterface) *Context
- func (engine *Engine) SetConfig(conf *ServerConfig) (err error)
- func (engine *Engine) SetMethodConfig(path string, mc *MethodConfig)
- func (engine *Engine) Start() error
- func (engine *Engine) Use(middleware ...Handler) IRoutes
- func (engine *Engine) UseFunc(middleware ...HandlerFunc) IRoutes
- type H
- type Handler
- type HandlerFunc
- type IRouter
- type IRoutes
- type MethodConfig
- type Param
- type Params
- type RouterGroup
- func (group *RouterGroup) BasePath() string
- func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
- func (group *RouterGroup) Handle(relativePath string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) Use(middleware ...Handler) IRoutes
- func (group *RouterGroup) UseFunc(middleware ...HandlerFunc) IRoutes
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { context.Context Stub cc.ChaincodeStubInterface Writer shim.ResponseWriter // Keys is a key/value pair exclusively for the context of each request. Keys map[string]interface{} Error error RoutePath string Params Params Init bool // contains filtered or unexported fields }
Context is the most important part. It allows us to pass variables between middleware, manage the flow, validate the JSON of a request and render a JSON response for example.
func (*Context) Abort ¶
func (c *Context) Abort()
Abort prevents pending handlers from being called. Note that this will not stop the current handler. Let's say you have an authorization middleware that validates that the current request is authorized. If the authorization fails (ex: the password does not match), call Abort to ensure the remaining handlers for this request are not called.
func (*Context) AbortWithStatus ¶
AbortWithStatus calls `Abort()` and writes the headers with the specified status code. For example, a failed attempt to authenticate a request could use: context.AbortWithStatus(401).
func (*Context) Get ¶
Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)
func (*Context) GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64.
func (*Context) GetUint64 ¶
GetUint64 returns the value associated with the key as an unsigned integer.
func (*Context) Next ¶
func (c *Context) Next()
Next should be used only inside middleware. It executes the pending handlers in the chain inside the calling handler. See example in godoc.
func (*Context) Set ¶
Set is used to store a new key/value pair exclusively for this context. It also lazy initializes c.Keys if it was not used previously.
type Engine ¶
type Engine struct { RouterGroup // If enabled, the url.RawPath will be used to find parameters. UseRawPath bool // If true, the path value will be unescaped. // If UseRawPath is false (by default), the UnescapePathValues effectively is true, // as url.Path gonna be used, which is already unescaped. UnescapePathValues bool // If enabled, the router checks if another method is allowed for the // current route, if the current request can not be routed. // If this is the case, the request is answered with 'Method Not Allowed' // and HTTP status code 405. // If no other Method is allowed, the request is delegated to the NotFound // handler. HandleMethodNotAllowed bool // contains filtered or unexported fields }
Engine is the framework's instance, it contains the muxer, middleware and configuration settings. Create an instance of Engine, by using New() or Default()
func DefaultServer ¶
func DefaultServer(conf *ServerConfig) *Engine
DefaultServer returns an Engine instance with the Recovery and Logger middleware already attached.
func NewServer ¶
func NewServer(conf *ServerConfig) *Engine
NewServer returns a new blank Engine instance without any middleware attached.
func (*Engine) InitMethod ¶
func (engine *Engine) InitMethod(handler ...HandlerFunc)
InitMethod sets the handlers called when chaincode init.
func (*Engine) Inject ¶
func (engine *Engine) Inject(pattern string, handlers ...HandlerFunc)
Inject is
func (*Engine) NoMethod ¶
func (engine *Engine) NoMethod(handlers ...HandlerFunc)
NoMethod sets the handlers called when... TODO.
func (*Engine) NoRoute ¶
func (engine *Engine) NoRoute(handlers ...HandlerFunc)
NoRoute adds handlers for NoRoute. It return a 404 code by default.
func (*Engine) SetConfig ¶
func (engine *Engine) SetConfig(conf *ServerConfig) (err error)
SetConfig is used to set the engine configuration. Only the valid config will be loaded.
func (*Engine) SetMethodConfig ¶
func (engine *Engine) SetMethodConfig(path string, mc *MethodConfig)
SetMethodConfig is used to set config on specified path
func (*Engine) Use ¶
Use attachs a global middleware to the router. ie. the middleware attached though Use() will be included in the handlers chain for every single request. Even 404, 405, static files... For example, this is the right place for a logger or error management middleware.
func (*Engine) UseFunc ¶
func (engine *Engine) UseFunc(middleware ...HandlerFunc) IRoutes
UseFunc attachs a global middleware to the router. ie. the middleware attached though UseFunc() will be included in the handlers chain for every single request. Even 404, 405, static files... For example, this is the right place for a logger or error management middleware.
type HandlerFunc ¶
type HandlerFunc func(*Context)
HandlerFunc request handler function.
func Recovery ¶
func Recovery() HandlerFunc
Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.
func (HandlerFunc) Serve ¶
func (h HandlerFunc) Serve(c *Context)
type IRouter ¶
type IRouter interface { IRoutes Group(string, ...HandlerFunc) *RouterGroup }
IRouter http router framework interface.
type IRoutes ¶
type IRoutes interface { UseFunc(...HandlerFunc) IRoutes Use(...Handler) IRoutes Handle(string, ...HandlerFunc) IRoutes }
IRoutes http router interface.
type MethodConfig ¶
MethodConfig is the fin server's method config model
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
type RouterGroup ¶
type RouterGroup struct { Handlers []HandlerFunc // contains filtered or unexported fields }
RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix and an array of handlers (middleware).
func (*RouterGroup) BasePath ¶
func (group *RouterGroup) BasePath() string
BasePath router group base path.
func (*RouterGroup) Group ¶
func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
Group creates a new router group. You should add all the routes that have common middlwares or the same path prefix. For example, all the routes that use a common middlware for authorization could be grouped.
func (*RouterGroup) Handle ¶
func (group *RouterGroup) Handle(relativePath string, handlers ...HandlerFunc) IRoutes
Handle registers a new request handle and middleware with the given path and method. The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes. See the example code in doc.
This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).
func (*RouterGroup) Use ¶
func (group *RouterGroup) Use(middleware ...Handler) IRoutes
Use adds middleware to the group, see example code in doc.
func (*RouterGroup) UseFunc ¶
func (group *RouterGroup) UseFunc(middleware ...HandlerFunc) IRoutes
UseFunc adds middleware to the group, see example code in doc.
type ServerConfig ¶
ServerConfig is the fin server config model