api

package
v0.0.0-...-d5bd7fa Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoUser = errors.New("No user stored in context")

ErrNotFound is returned when no data could be found

Functions

func ExpiresAt

func ExpiresAt(ctx context.Context) (int64, error)

ExpiresAt gets the expiresAt time for the specified context

func User

func User(ctx context.Context) (string, error)

User gets the user for the specified context

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API represents a Rest API instance

func NewAPI

func NewAPI(cfg config.API, prefix string) (*API, error)

NewAPI creates a new Rest API instance

func (*API) AttachModuleDelete

func (a *API) AttachModuleDelete(path string, f func(http.ResponseWriter, *http.Request))

AttachModuleDelete registers a new DELETE handler for the API

func (*API) AttachModuleGet

func (a *API) AttachModuleGet(path string, f func(http.ResponseWriter, *http.Request))

AttachModuleGet registers a new GET handler for the API

func (*API) AttachModulePost

func (a *API) AttachModulePost(path string, f func(http.ResponseWriter, *http.Request))

AttachModulePost registers a new POST handler for the API

func (*API) AttachModulePut

func (a *API) AttachModulePut(path string, f func(http.ResponseWriter, *http.Request))

AttachModulePut registers a new PUT handler for the API

func (*API) Init

func (a *API) Init() error

Init the API instance

func (*API) InitJWT

func (a *API) InitJWT() error

InitJWT initializes the protected part of the API

func (*API) ProtectedAttachModuleDelete

func (a *API) ProtectedAttachModuleDelete(path string, f func(http.ResponseWriter, *http.Request))

ProtectedAttachModuleDelete registers a new GET handler for the API (needs valid authentication token)

func (*API) ProtectedAttachModuleGet

func (a *API) ProtectedAttachModuleGet(path string, f func(http.ResponseWriter, *http.Request))

ProtectedAttachModuleGet registers a new GET handler for the API (needs valid authentication token)

func (*API) ProtectedAttachModulePost

func (a *API) ProtectedAttachModulePost(path string, f func(http.ResponseWriter, *http.Request))

ProtectedAttachModulePost registers a new GET handler for the API (needs valid authentication token)

func (*API) ProtectedAttachModulePut

func (a *API) ProtectedAttachModulePut(path string, f func(http.ResponseWriter, *http.Request))

ProtectedAttachModulePut registers a new GET handler for the API (needs valid authentication token)

func (*API) Run

func (a *API) Run(ctx context.Context) error

Run the REST API (blocking)

func (*API) ValidateJWTMiddleware

func (a *API) ValidateJWTMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ValidateJWTMiddleware is used to validate a JWT token

type Claims

type Claims struct {
	// TODO: Maybe it is not a good idea to use the username itself in jwt Claim
	Username string `json:"username"`
	jwt.StandardClaims
}

Claims contains all the content stored in the JWT token

type Credentials

type Credentials struct {
	Password string `json:"password"`
	Username string `json:"username"`
}

Credentials is a struct that models the structure of a user, both in the request body, and in the DB

Jump to

Keyboard shortcuts

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