Documentation
¶
Index ¶
- Constants
- func AddRequestError(r *http.Request, err error)
- func BadRequest(rw http.ResponseWriter, body interface{})
- func Clear(r *http.Request)
- func Created(rw http.ResponseWriter, body interface{})
- func Forbidden(rw http.ResponseWriter, body interface{})
- func GetCurrentUser(r *http.Request) (*account.User, error)
- func GetRequestError(r *http.Request) (error, bool)
- func NoContent(rw http.ResponseWriter)
- func NotFound(rw http.ResponseWriter, body interface{})
- func Ok(rw http.ResponseWriter, body interface{})
- func SetCurrentUser(r *http.Request, user *account.User)
- func Unauthorized(rw http.ResponseWriter, body interface{})
- type Api
- func (api *Api) AddHook(wh account.Hook)
- func (api *Api) EventNotifier(ev Event)
- func (api *Api) Handler() http.Handler
- func (api *Api) ListenEvents()
- func (api *Api) Login(email, password string) (*account.Token, error)
- func (api *Api) PubSub(pubsub account.PubSub)
- func (api *Api) Run()
- func (api *Api) SetAuth(auth auth.Authenticatable)
- func (api *Api) Storage(store account.Storable)
- type AuthorizationHandler
- type CollectionSerializer
- type Event
- type HTTPResponse
- type Router
- func (router *Router) AddHandler(args RouterArguments)
- func (router *Router) AddMiddleware(pathPrefix string, h http.Handler)
- func (router *Router) AddSubrouter(pathPrefix string) *mux.Router
- func (router *Router) Handler() http.Handler
- func (router *Router) NotFoundHandler(h http.Handler)
- func (router *Router) Subrouter(pathPrefix string) *mux.Router
- type RouterArguments
Constants ¶
const ( DEFAULT_EVENTS_CHANNEL_LEN = 100 DEFAULT_PORT = ":8000" DEFAULT_TIMEOUT = 10 * time.Second )
const ( ErrRequestKey string = "RequestError" CurrentUser string = "CurrentUser" )
Variables ¶
This section is empty.
Functions ¶
func AddRequestError ¶
Add an error in the request context.
func BadRequest ¶
func BadRequest(rw http.ResponseWriter, body interface{})
func Created ¶
func Created(rw http.ResponseWriter, body interface{})
func Forbidden ¶
func Forbidden(rw http.ResponseWriter, body interface{})
func GetCurrentUser ¶
Get the user from the request context and check if it's still valid.
func GetRequestError ¶
Get an error from the request context. Return nil and false if nothing is found. Otherwise, return the error.
func NoContent ¶
func NoContent(rw http.ResponseWriter)
func NotFound ¶
func NotFound(rw http.ResponseWriter, body interface{})
func Ok ¶
func Ok(rw http.ResponseWriter, body interface{})
func SetCurrentUser ¶
Set the current user in the request context.
func Unauthorized ¶
func Unauthorized(rw http.ResponseWriter, body interface{})
Types ¶
type Api ¶
type Api struct {
Events chan Event
// contains filtered or unexported fields
}
func (*Api) AddHook ¶
This is intend to be used when loading the api only, just to connect the apihub with apihub-gateway. TODO: Need to improve this.
func (*Api) EventNotifier ¶
func (*Api) ListenEvents ¶
func (api *Api) ListenEvents()
func (*Api) Login ¶
Split Authenticate and CreateUserToken because we can override only the authentication method and still use the token method.
func (*Api) PubSub ¶
Allow to override the default pubsub engine. To be compatible, it is needed to implement the Subscription interface.
func (*Api) SetAuth ¶
func (api *Api) SetAuth(auth auth.Authenticatable)
Allow to override the default authentication method. To be compatible, it is needed to implement the Authenticatable interface.
type AuthorizationHandler ¶
type CollectionSerializer ¶
type CollectionSerializer struct {
Items interface{} `json:"items"`
Count int `json:"item_count"`
}
func (*CollectionSerializer) Serializer ¶
func (cs *CollectionSerializer) Serializer() string
type HTTPResponse ¶
type HTTPResponse struct {
ContentType string `json:"-"`
StatusCode int `json:"-"`
Body interface{} `json:"body,omitempty"`
}
func (*HTTPResponse) ToJson ¶
func (h *HTTPResponse) ToJson() []byte
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) AddHandler ¶
func (router *Router) AddHandler(args RouterArguments)
func (*Router) AddMiddleware ¶
func (*Router) NotFoundHandler ¶
type RouterArguments ¶
type RouterArguments struct {
Handler http.HandlerFunc
Path string
PathPrefix string
Methods []string
}