handler

package
v0.0.0-...-d04c61c Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthHeader = "Authorization"
	AuthType   = "Targetblank"
)

Expected authorization header configuration.

View Source
const (
	ErrPageNotFound    = "page not found"
	ErrInvalidEmail    = "invalid email address"
	ErrInvalidPassword = "password is too short"
	ErrGeneric         = "something went wrong"
)

Common client error messages.

Variables

View Source
var (

	// ErrRestrictedToken is returned when authenticating restricted tokens.
	ErrRestrictedToken = fmt.Errorf("restricted token")
)

Functions

func CreateRestrictedToken

func CreateRestrictedToken(key string, identity string) (string, error)

CreateRestrictedToken creates a new authentication token that expires.

func CreateToken

func CreateToken(key string, identity string) (string, error)

CreateToken creates a new authentication token that never expires.

func New

New creates a lambda handler from a Handler and a Config.

Types

type Error

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

Error adds a status code to the error type.

func ClientErr

func ClientErr(format string, a ...interface{}) *Error

ClientErr creates a new 400 status function error.

func InternalErr

func InternalErr(format string, a ...interface{}) *Error

InternalErr creates a new function error with an encrypted message.

func ObfuscatedAuthErr

func ObfuscatedAuthErr() *Error

ObfuscatedAuthErr creates a 404 status function error. Should be used to hide the existence of pages.

func (*Error) Code

func (e *Error) Code() int

Code returns the error's http status code.

type Handler

type Handler func(*Request, *Response) *Error

Handler is a custom type representing a lambda handler.

type Request

Request replaces the api gateway request event.

func (*Request) Authenticate

func (r *Request) Authenticate(key, identity string) (*time.Time, error)

Authenticate validates the token in the request. Returns time at which token was issued and/or an authentication error. Returns ErrRestrictedToken if token is restricted.

func (*Request) Param

func (r *Request) Param(n string) (string, *Error)

Param reads a path parameter from the request.

type Response

Response replaces the api gateway response event.

func (*Response) ContentType

func (r *Response) ContentType(t string)

ContentType adds the content-type header to the request.

Jump to

Keyboard shortcuts

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