Documentation ¶
Overview ¶
Package rocha is a Hyperledger Fabric Chaincode Router with Middleware support
Index ¶
- func NotFoundHandler(c Context) pb.Response
- type Context
- type Handler
- type Middleware
- type Router
- func (r *Router) Handle(method string, handler Handler, middlewares ...Middleware) *Router
- func (r *Router) Invoke(stub shim.ChaincodeStubInterface, method string, args []string) pb.Response
- func (r *Router) NotFoundHandler(handler Handler) *Router
- func (r *Router) Use(middlewares ...Middleware) *Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NotFoundHandler ¶
NotFoundHandler is a simple handler which returns a not found message with the method's name
Types ¶
type Context ¶
type Context interface { // Method returns the method's name Method() (method string) // Args returns the sent arguments Args() (args []string) // Stub returns the internal ChaincodeStub for this context Stub() shim.ChaincodeStubInterface // Set stores a value in the current context Set(key string, value interface{}) // Get returns a value in the current context Get(key string) (value interface{}, exists bool) // Value returns a value stored in the context like Get, but does no // checking if the value actually exists Value(key string) (value interface{}) // String returns a value stored in the context casted to a string. // if no value is found, a empty string is returned String(key string) (value string) // Int returns a value stored in the context casted to a int. If no // value is found, a zero int is returned Int(key string) (value int) }
Context contains all necessary functions for interacting with the underlying blockchain infrastructure and a simple key-value store for middleware/application internal usage
func NewContext ¶
func NewContext(stub shim.ChaincodeStubInterface, method string, args []string) Context
NewContext creates a new context with the middlewares and handlers to be called
type Handler ¶
Handler is a function called to process a chaincode request
func Chain ¶
func Chain(h Handler, middlewares ...Middleware) Handler
Chain chains a series of middlewares to a new Handler. Middlewares are chained in the reverse order. If this function is called with
rocha.Chain(h, m4, m3, m2, m1) == m1(m2(m3(m4(h))))
type Middleware ¶
Middleware is function which wraps a Handler with some functionality, returning a new Handler with wrapped code
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router register routes to be invoked according to their method names
func (*Router) Handle ¶
func (r *Router) Handle(method string, handler Handler, middlewares ...Middleware) *Router
Handle adds a new route to the router, overwriting a previous router by this name
func (*Router) NotFoundHandler ¶
NotFoundHandler sets a not found handler for this router
func (*Router) Use ¶
func (r *Router) Use(middlewares ...Middleware) *Router
Use adds a new middleware