database

package
v0.0.0-...-2a740e3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(db Datastore) func(http.Handler) http.Handler

Middleware packs a pointer to the datastore into context

Types

type Datastore

type Datastore interface {
	AddManualSnowdepthMeasurement(latitude, longitude, depth float64) (*models.Snowdepth, error)
	AddSnowdepthMeasurement(device *string, latitude, longitude, depth float64, when string) (*models.Snowdepth, error)
	GetLatestSnowdepths() ([]models.Snowdepth, error)
	GetLatestSnowdepthsForDevice(device string) ([]models.Snowdepth, error)
}

Datastore is an interface that is used to inject the database into different handlers to improve testability

func GetFromContext

func GetFromContext(ctx context.Context) (Datastore, error)

GetFromContext extracts the database wrapper, if any, from the provided context

func NewDatabaseConnection

func NewDatabaseConnection() (Datastore, error)

NewDatabaseConnection initializes a new connection to the database and wraps it in a Datastore

Jump to

Keyboard shortcuts

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