rest

package
v0.0.0-...-99ef519 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: Unlicense Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleAdmin = "ADMIN"
	RoleUser  = "USER"
)

These are the expected values for Claims.Roles.

View Source
const Key ctxKey = 1

Key is used to store/retrieve a Claims value from a context.Context.

Variables

This section is empty.

Functions

func ExtractJwt

func ExtractJwt(h http.Header) string

ExtractJwt extracts the jwt token from the header line.

func HMACKeyFunc

func HMACKeyFunc(t *jwt.Token) (interface{}, error)

HMACKeyFunc verifies the token signing method and returns the shared HMAC secret as key used for signature validation.

func IDPAudience

func IDPAudience() string

IDPAudience returns the configured issuer by consulting the environment variable "IDP_ISSUER".

func IDPIssuer

func IDPIssuer() string

IDPIssuer returns the configured issuer by consulting the environment variable "IDP_ISSUER".

func RS256KeyFunc

func RS256KeyFunc(t *jwt.Token) (interface{}, error)

RS256KeyFunc verifies the token signing method and returns the public signing key, matching the key identified by the tokens "kid" header value, used for signature validation.

func Realm

func Realm() string

Realm returns the configured realm by consulting the environment variable "AUTH_REALM".

Types

type ActivitiesPresenter

type ActivitiesPresenter struct {
}

ActivitiesPresenter implements the presenter interface.

func NewActivitiesPresenter

func NewActivitiesPresenter() ActivitiesPresenter

NewActivitiesPresenter instantiates an activities presenter.

func (ActivitiesPresenter) Present

func (ActivitiesPresenter) Present(i interface{}) CacheableActivities

Present knows how to present the activities list combined with the last modified date.

type Adapter

type Adapter struct {
	R *mux.Router
	// contains filtered or unexported fields
}

Adapter converts HTTP request data into domain objects.

func NewAdapter

func NewAdapter() Adapter

NewAdapter instantiates an adapter.

func (Adapter) ActivitiesHandler

func (a Adapter) ActivitiesHandler(uc usecase.Activities) Handler

ActivitiesHandler returns a handler that knows how to retrieve activities for a user.

func (Adapter) CreateActivityHandler

func (a Adapter) CreateActivityHandler(uc usecase.CreateActivity) Handler

CreateActivityHandler returns a handler that knows how to create an activity.

func (Adapter) CreateBookingHandler

func (a Adapter) CreateBookingHandler(uc usecase.CreateBooking) Handler

CreateBookingHandler returns a handler that knows how to create a booking.

func (Adapter) CreateCustomerHandler

func (a Adapter) CreateCustomerHandler(uc usecase.CreateCustomer) Handler

CreateCustomerHandler returns a handler that knows how to create a customer.

func (Adapter) CreateInvoiceHandler

func (a Adapter) CreateInvoiceHandler(uc usecase.CreateInvoice) Handler

CreateInvoiceHandler returns a handler that knows how to create an invoice.

func (Adapter) CreateProjectHandler

func (a Adapter) CreateProjectHandler(uc usecase.CreateProject) Handler

CreateProjectHandler returns a handler that knows how to create a project.

func (Adapter) CreateRateHandler

func (a Adapter) CreateRateHandler(uc usecase.CreateRate) Handler

CreateRateHandler returns a handler that knows how to create a rate.

func (Adapter) DeleteBookingHandler

func (a Adapter) DeleteBookingHandler(uc usecase.DeleteBooking) Handler

DeleteBookingHandler returns a handler that knows how to delete a booking.

func (Adapter) GetInvoiceHandler

func (a Adapter) GetInvoiceHandler(uc usecase.GetInvoice) Handler

GetInvoiceHandler returns a handler that knows how to deliver an invoice in either JSON or PDF format.

func (Adapter) Handle

func (a Adapter) Handle(path string, handler Handler) *mux.Route

Handle creates a route and maps it to a path and handler.

func (Adapter) InvoicePresenter

func (a Adapter) InvoicePresenter(w http.ResponseWriter, r *http.Request) (InvoicePresenter, bool)

InvoicePresenter returns a presenter matching the 'Accept' request header.

func (Adapter) ListenAndServe

func (a Adapter) ListenAndServe()

ListenAndServe launches a web server on port 8080.

func (Adapter) ListenAndServeTLS

func (a Adapter) ListenAndServeTLS()

ListenAndServeTLS launches a web server on port 8080.

func (Adapter) OAuth2AccessTokenHandler

func (a Adapter) OAuth2AccessTokenHandler() Handler

OAuth2AccessTokenHandler exchanges the oauth code grant for an access token.

func (Adapter) UpdateInvoiceHandler

func (a Adapter) UpdateInvoiceHandler(updateInvoice usecase.UpdateInvoice) Handler

UpdateInvoiceHandler returns a handler that knows how to update an ivoice.

type CacheableActivities

type CacheableActivities struct {
	Activities   []byte
	LastModified time.Time
}

CacheableActivities decorates activities with last modified date.

type Claims

type Claims struct {
	Roles []string `json:"roles"`
	jwt.StandardClaims
}

Claims represents the authorization claims transmitted via a JWT.

func (Claims) Authorized

func (c Claims) Authorized(roles ...string) bool

Authorized returns true if claims has at least one of the provided roles.

func (Claims) Valid

func (c Claims) Valid(helper *jwt.ValidationHelper) error

Valid is called during the parsing of a token.

type DefaultPresenter

type DefaultPresenter struct {
}

DefaultPresenter ...

func NewDefaultPresenter

func NewDefaultPresenter() DefaultPresenter

NewDefaultPresenter ...

func (DefaultPresenter) Present

func (p DefaultPresenter) Present(i interface{})

Present ...

type Embedded

type Embedded struct {
	Bookings []domain.Booking `json:"bookings,omitempty"`
}

Embedded wraps only bookings for now.

type HALInvoice

type HALInvoice struct {
	domain.Invoice
	Links    map[domain.Operation]Link `json:"_links"`              // _links
	Embedded *Embedded                 `json:"_embedded,omitempty"` // _embedded
}

HALInvoice decorates an invoice with HAL conform _link elements.

func NewHALInvoice

func NewHALInvoice(i domain.Invoice) HALInvoice

NewHALInvoice instantiates a HAL invoice.

type HALInvoicePresenter

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

HALInvoicePresenter structure.

func NewHALInvoicePresenter

func NewHALInvoicePresenter(w http.ResponseWriter) HALInvoicePresenter

NewHALInvoicePresenter instantiates a HAL invoice presenter.

func (HALInvoicePresenter) Present

func (p HALInvoicePresenter) Present(i interface{})

Present knows how to present a HAL invoice.

type Handler

type Handler func(ctx context.Context, w http.ResponseWriter, r *http.Request)

Handler is a type that handles http requests.

func BasicAuth

func BasicAuth(next Handler) Handler

BasicAuth decorator

func DigestAuth

func DigestAuth(next Handler) Handler

DigestAuth decorator

func JWTAuth

func JWTAuth(next Handler) Handler

JWTAuth decorator

func OAuth2AccessCodeGrant

func OAuth2AccessCodeGrant(next Handler) Handler

OAuth2AccessCodeGrant decorator makes sure the redirect URI is valid.

type InvoicePresenter

type InvoicePresenter interface {
	Present(i interface{})
}

InvoicePresenter ...

type JSONInvoicePresenter

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

JSONInvoicePresenter ...

func NewJSONInvoicePresenter

func NewJSONInvoicePresenter(w http.ResponseWriter) JSONInvoicePresenter

NewJSONInvoicePresenter ...

func (JSONInvoicePresenter) Present

func (p JSONInvoicePresenter) Present(i interface{})

Present ...

type Link struct {
	Href string `json:"href"`
}

Link models a HAL link.

type PDFInvoicePresenter

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

PDFInvoicePresenter ...

func NewPDFInvoicePresenter

func NewPDFInvoicePresenter(w http.ResponseWriter, r *http.Request) PDFInvoicePresenter

NewPDFInvoicePresenter ...

func (PDFInvoicePresenter) Present

func (p PDFInvoicePresenter) Present(i interface{})

Present ...

Jump to

Keyboard shortcuts

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