core

package
v0.0.0-...-4b8b255 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const APIVersionMajor uint = 0
View Source
const APIVersionMinor uint = 1

Variables

This section is empty.

Functions

func BindAndValidate

func BindAndValidate(ctx echo.Context, i interface{}) error

Ease of use method, when binding & validation is needed.

func OptimiseImageToJPEG

func OptimiseImageToJPEG(image []byte, maxSize int) ([]byte, error)

Optimises an image to JPEG format, ensuring that the image is no larger than maxSize

func PopElement

func PopElement[T comparable](toPop T, items []T) []T

func ValueOrDefault

func ValueOrDefault[V comparable](value *V, def V) V

Types

type AuthenticatedUser

type AuthenticatedUser struct {
	UserID   uuid.UUID `json:"userId"`
	Username string    `json:"username"`
	IsAdmin  bool      `json:"isAdmin"`
}

func GetAuthenticatedUserFromContext

func GetAuthenticatedUserFromContext(ctx echo.Context) (AuthenticatedUser, error)

Get the authenticated user

type CreateLogin

type CreateLogin struct {
	Username string `json:"username" validate:"required"`
	Password string `json:"password" validate:"required"`
}

type JWTClaims

type JWTClaims struct {
	Username string `json:"username"`
	IsAdmin  bool   `json:"isAdmin"`
	jwt.RegisteredClaims
}

func (*JWTClaims) ToAuthenticatedUser

func (c *JWTClaims) ToAuthenticatedUser() (AuthenticatedUser, error)

type LoginToken

type LoginToken struct {
	Type   string    `json:"type"`
	Token  string    `json:"token"`
	Expiry time.Time `json:"expiry"`
}

func CreateAuthenticationToken

func CreateAuthenticationToken(user AuthenticatedUser, secretKey []byte) (LoginToken, error)

Create token for authentication

type PaginationParams

type PaginationParams struct {
	Page    uint `query:"page" validate:"required,gt=0"`
	PerPage uint `query:"perPage" validate:"required,gt=0,lte=120"`
}

type PantryItemsFilterParams

type PantryItemsFilterParams struct {
	PaginationParams
	Name       string     `query:"name"`
	Labels     []string   `query:"label"`
	LocationId *uuid.UUID `query:"locationId"`
	Expired    *bool      `query:"expired"`
}

type RecipesFilterParams

type RecipesFilterParams struct {
	PaginationParams
	Title         *string  `query:"title"`
	Labels        []string `query:"label"`
	Freezable     *bool    `query:"freezable"`
	MicrowaveOnly *bool    `query:"microwaveOnly"`
}

type SelectField

type SelectField string

func (*SelectField) UnmarshalJSON

func (sf *SelectField) UnmarshalJSON(data []byte) error

type SelectedUpdate

type SelectedUpdate[T any] struct {
	Fields []SelectField `json:"fields" validate:"required"`
	Model  T             `json:"model" validate:"required"`
}

func (*SelectedUpdate[T]) FieldsAsString

func (su *SelectedUpdate[T]) FieldsAsString() []string

Jump to

Keyboard shortcuts

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