api

package
v0.0.0-...-14179a4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2015 License: BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_EVENTS_CHANNEL_LEN = 100
	DEFAULT_PORT               = ":8000"
	DEFAULT_TIMEOUT            = 10 * time.Second
)
View Source
const (
	ErrRequestKey string = "RequestError"
	CurrentUser   string = "CurrentUser"
)

Variables

This section is empty.

Functions

func AddRequestError

func AddRequestError(r *http.Request, err error)

Add an error in the request context.

func BadRequest

func BadRequest(rw http.ResponseWriter, body interface{})

func Clear

func Clear(r *http.Request)

Clear removes all values stored for a given request.

func Created

func Created(rw http.ResponseWriter, body interface{})

func Forbidden

func Forbidden(rw http.ResponseWriter, body interface{})

func GetCurrentUser

func GetCurrentUser(r *http.Request) (*account.User, error)

Get the user from the request context and check if it's still valid.

func GetRequestError

func GetRequestError(r *http.Request) (error, bool)

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

func SetCurrentUser(r *http.Request, user *account.User)

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 NewApi

func NewApi(store account.Storable, pubsub account.PubSub) *Api

func (*Api) AddHook

func (api *Api) AddHook(wh account.Hook)

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 *Api) EventNotifier(ev Event)

func (*Api) Handler

func (api *Api) Handler() http.Handler

func (*Api) ListenEvents

func (api *Api) ListenEvents()

func (*Api) Login

func (api *Api) Login(email, password string) (*account.Token, error)

Split Authenticate and CreateUserToken because we can override only the authentication method and still use the token method.

func (*Api) PubSub

func (api *Api) PubSub(pubsub account.PubSub)

Allow to override the default pubsub engine. To be compatible, it is needed to implement the Subscription interface.

func (*Api) Run

func (api *Api) Run()

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.

func (*Api) Storage

func (api *Api) Storage(store account.Storable)

Allow to override the default storage engine. To be compatible, it is needed to implement the Storable interface.

type AuthorizationHandler

type AuthorizationHandler func(w http.ResponseWriter, r *http.Request, user *account.User)

type CollectionSerializer

type CollectionSerializer struct {
	Items interface{} `json:"items"`
	Count int         `json:"item_count"`
}

func (*CollectionSerializer) Serializer

func (cs *CollectionSerializer) Serializer() string

type Event

type Event interface {
	Data() []byte
	Name() 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 NewRouter

func NewRouter() *Router

func (*Router) AddHandler

func (router *Router) AddHandler(args RouterArguments)

func (*Router) AddMiddleware

func (router *Router) AddMiddleware(pathPrefix string, h http.Handler)

func (*Router) AddSubrouter

func (router *Router) AddSubrouter(pathPrefix string) *mux.Router

func (*Router) Handler

func (router *Router) Handler() http.Handler

func (*Router) NotFoundHandler

func (router *Router) NotFoundHandler(h http.Handler)

func (*Router) Subrouter

func (router *Router) Subrouter(pathPrefix string) *mux.Router

type RouterArguments

type RouterArguments struct {
	Handler    http.HandlerFunc
	Path       string
	PathPrefix string
	Methods    []string
}

Jump to

Keyboard shortcuts

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