api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2018 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ElasticIndex = "lindeb"
View Source
const ElasticType = "link"

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	DB      *db.DB
	Elastic *elastic.Client
	// contains filtered or unexported fields
}

API contains objects needed by the API handlers to function.

func Create added in v0.3.0

func Create(db *db.DB, elastic *elastic.Client) *API
func (api *API) AccessLink(w http.ResponseWriter, r *http.Request)

AccessLink is a method proxy for the handlers of /api/link/<id>

func (*API) AccessSetting added in v0.3.0

func (api *API) AccessSetting(w http.ResponseWriter, r *http.Request)

func (*API) AccessTag

func (api *API) AccessTag(w http.ResponseWriter, r *http.Request)

AccessTag is a method proxy for the handlers of /api/tag/<id>

func (*API) AddHandler

func (api *API) AddHandler(router *mux.Router)

AddHandler registers all the API paths.

func (*API) AddTag

func (api *API) AddTag(w http.ResponseWriter, r *http.Request)

func (*API) AuthMiddleware

func (api *API) AuthMiddleware(next http.Handler) http.Handler

AuthMiddleware provides a HTTP handler middleware that loads the user data of the sender to the request context.

If the user is not logged in, HTTP Unauthorized is returned and the next handler is not called.

func (api *API) BrowseLinks(w http.ResponseWriter, r *http.Request)

BrowseLinks is the handler for GET /api/links

func (api *API) DeleteLink(w http.ResponseWriter, r *http.Request)

DeleteLink is the handler for DELETE /api/link/<id>

func (*API) DeleteSetting added in v0.3.0

func (api *API) DeleteSetting(w http.ResponseWriter, r *http.Request)

func (*API) DeleteTag

func (api *API) DeleteTag(w http.ResponseWriter, r *http.Request)
func (api *API) EditLink(w http.ResponseWriter, r *http.Request)

EditLink is the handler for PUT /api/link/<id>

func (*API) EditTag

func (api *API) EditTag(w http.ResponseWriter, r *http.Request)

EditTag is the handler for PUT /api/link/<id>

func (api *API) GetLink(w http.ResponseWriter, r *http.Request)

GetLink is the handler for GET /api/link/<id>

func (*API) GetLinkFromContext

func (api *API) GetLinkFromContext(r *http.Request) *db.Link

GetLinkFromContext gets the database link object from the context of the given request.

Calling this function with a request that did not go through the link getter middleware is strictly forbidden and will cause a panic.

func (*API) GetSetting added in v0.3.0

func (api *API) GetSetting(w http.ResponseWriter, r *http.Request)

func (*API) GetSettings added in v0.3.0

func (api *API) GetSettings(w http.ResponseWriter, r *http.Request)

func (*API) GetTag

func (api *API) GetTag(w http.ResponseWriter, r *http.Request)

GetTag is the handler for GET /api/tag/<id>

func (*API) GetTagFromContext

func (api *API) GetTagFromContext(r *http.Request) *db.Tag

GetTagFromContext gets the database tag object from the context of the given request.

Calling this function with a request that did not go through the tag getter middleware is strictly forbidden and will cause a panic.

func (*API) GetUser

func (api *API) GetUser(r *http.Request) *db.User

GetUser gets the apiUser who sent the request, or nil if the sender is not logged in.

func (*API) GetUserFromContext

func (api *API) GetUserFromContext(r *http.Request) *db.User

GetUserFromContext gets the database user object from the context of the given request.

Calling this function with a request that did not go through the auth check middleware is strictly forbidden and will cause a panic.

func (api *API) ImportLinks(w http.ResponseWriter, r *http.Request)

func (*API) LinkMiddleware

func (api *API) LinkMiddleware(next http.Handler) http.Handler

LinkMiddleware provides a HTTP handler middleware that loads the data of the link with the requested ID to the request context.

You must call the authentication middleware BEFORE this function, as this depends on the user being logged in.

If the request path doesn't contain the id field, HTTP Bad Request is returned. If the requested link does not exist or is not owned by the current user, HTTP Not Found is returned. In both error cases, the next handler is not called.

func (*API) ListTags

func (api *API) ListTags(w http.ResponseWriter, r *http.Request)

func (*API) Login

func (api *API) Login(w http.ResponseWriter, r *http.Request)

Login checks the provided password and generates a new authentication token that is sent back to the apiUser.

func (*API) Logout

func (api *API) Logout(w http.ResponseWriter, r *http.Request)

Logout invalidates the authentication token sent with the request.

func (*API) Register

func (api *API) Register(w http.ResponseWriter, r *http.Request)

Register creates a new apiUser and logs in.

func (api *API) SaveLink(w http.ResponseWriter, r *http.Request)

SaveLink is a handler for POST /api/link/save

func (*API) StartElasticQueue added in v0.3.0

func (api *API) StartElasticQueue()

func (*API) Stop added in v0.3.0

func (api *API) Stop()

func (*API) TagMiddleware

func (api *API) TagMiddleware(next http.Handler) http.Handler

TagMiddleware provides a HTTP handler middleware that loads the data of the tag with the requested ID to the request context.

You must call the authentication middleware BEFORE this function, as this depends on the user being logged in.

If the request path doesn't contain the id field, HTTP Bad Request is returned. If the requested tag does not exist or is not owned by the current user, HTTP Not Found is returned. In both error cases, the next handler is not called.

func (*API) UpdateAuth added in v0.2.0

func (api *API) UpdateAuth(w http.ResponseWriter, r *http.Request)

func (*API) UpdateSetting added in v0.3.0

func (api *API) UpdateSetting(w http.ResponseWriter, r *http.Request)
func (api *API) ValidateLink(w http.ResponseWriter, link apiLink) bool

func (*API) ValidateTag added in v1.0.0

func (api *API) ValidateTag(w http.ResponseWriter, tag *db.Tag) bool

Jump to

Keyboard shortcuts

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