mw

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsHandlerFunc

func AsHandlerFunc(a Action) http.HandlerFunc

AsHandlerFunc is a helper wrapper to make implementing actions easier

func NewAuthMiddleware

func NewAuthMiddleware(users provision.Twins) mux.MiddlewareFunc

NewAuthMiddleware creates a new AuthMiddleware using jwt signed by the caller

func TwinID

func TwinID(ctx context.Context) uint32

TwinID extracts twin id from request

func TwinPublicKey

func TwinPublicKey(ctx context.Context) ed25519.PublicKey

TwinPublicKey extracts twin public key from request

Types

type Action

type Action func(r *http.Request) (interface{}, Response)

Action interface

type Response

type Response interface {
	Status() int
	Err() error

	// header getter
	Header() http.Header
	// header setter
	WithHeader(k, v string) Response
}

Response interface

func Accepted

func Accepted() Response

Accepted response

func BadRequest

func BadRequest(err error) Response

BadRequest result

func Conflict

func Conflict(err error) Response

Conflict response

func Created

func Created() Response

Created return a created response

func Error

func Error(err error, code ...int) Response

Error generic error response

func Forbidden

func Forbidden(err error) Response

Forbidden response

func NoContent

func NoContent() Response

NoContent response

func NotFound

func NotFound(err error) Response

NotFound response

func Ok

func Ok() Response

Ok return a ok response

func PaymentRequired

func PaymentRequired(err error) Response

PaymentRequired result

func UnAuthorized

func UnAuthorized(err error) Response

UnAuthorized response

func Unavailable

func Unavailable(err error) Response

Unavailable returned when server is too busy

type UserMap

type UserMap map[uint32]ed25519.PublicKey

UserMap implements provision.Twins for the users collections

func NewUserMap

func NewUserMap() UserMap

NewUserMap create a new UserMap that uses the users collection to find the key

func (UserMap) AddKeyFromHex

func (u UserMap) AddKeyFromHex(id uint32, key string) error

AddKeyFromHex adds a user key to map from a hex string

func (UserMap) GetKey

func (u UserMap) GetKey(id uint32) ([]byte, error)

GetKey implements interface

Jump to

Keyboard shortcuts

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