httpd

package
v0.0.0-...-5745a54 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: ISC Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const AuthCookieName = "idiot_session_id"

Variables

This section is empty.

Functions

func Log

func Log(log *slog.Logger) func(http.Handler) http.Handler

func WError

func WError(w http.ResponseWriter, r *http.Request, err error, code int, m string) *api.Response

Types

type AlertStore

type AlertStore interface {
	GetAlerts(ctx context.Context) ([]scylla.Alert, error)
}

type DBStore

type DBStore interface {
	UserStore
	WebpushStore
	SensorStore
	AlertStore
}

type ReadingSubscriber

type ReadingSubscriber interface {
	Subscribe(k string, ctx context.Context, sub func(ctx context.Context, message redis.SensorReading))
	Unsubscribe(k string)
}

type SensorStore

type SensorStore interface {
	GetSensors(ctx context.Context) ([]scylla.SensorInfoWithLastReading, error)
	RenameSensor(ctx context.Context, id string, name string) error
}

type Service

type Service struct {
	CDNHost string
	// contains filtered or unexported fields
}

func New

func New(dbstore DBStore, sessionStore SessionStore, readings ReadingSubscriber, CDNHost string) *Service

func (Service) AuthLogin

func (s Service) AuthLogin(w http.ResponseWriter, r *http.Request) *api.Response

Login (POST /auth/login)

func (Service) AuthLogout

func (s Service) AuthLogout(w http.ResponseWriter, r *http.Request) *api.Response

Logout (POST /auth/logout)

func (Service) AuthMiddleware

func (s Service) AuthMiddleware(next http.Handler) http.Handler

func (Service) CreateUser

func (s Service) CreateUser(w http.ResponseWriter, r *http.Request) *api.Response

(POST /users)

func (Service) DeleteUserByID

func (us Service) DeleteUserByID(w http.ResponseWriter, r *http.Request, id ulid.ULID) *api.Response

(DELETE /users/{id})

func (*Service) GetAlerts

func (s *Service) GetAlerts(w http.ResponseWriter, r *http.Request) *api.Response

func (*Service) GetSensors

func (s *Service) GetSensors(w http.ResponseWriter, r *http.Request) *api.Response

func (*Service) GetSensorsLive

func (s *Service) GetSensorsLive(w http.ResponseWriter, r *http.Request) *api.Response

GetSensorsLive returns the live data for all of the available sensors when it's available It's all streamed through a websocket (GET /sensors/live)

func (Service) GetUserByID

func (us Service) GetUserByID(w http.ResponseWriter, r *http.Request, id ulid.ULID) *api.Response

(GET /users/{id})

func (Service) GetUsers

func (us Service) GetUsers(w http.ResponseWriter, r *http.Request) *api.Response

(GET /users)

func (*Service) GetWebpushKey

func (s *Service) GetWebpushKey(w http.ResponseWriter, r *http.Request) *api.Response

Send a webpush notification key

(GET /notifications/webpush)

func (Service) PermissionsMiddleware

func (s Service) PermissionsMiddleware(next http.Handler) http.Handler

func (*Service) RegisterWebpush

func (s *Service) RegisterWebpush(w http.ResponseWriter, r *http.Request) *api.Response

Send a webpush notification registration payload (POST /notifications/webpush)

func (*Service) RenameSensor

func (s *Service) RenameSensor(w http.ResponseWriter, r *http.Request, id string, params api.RenameSensorParams) *api.Response

(POST /sensors/{id}/rename)

type SessionStore

type SessionStore interface {
	NewSession(ctx context.Context, userID ulid.ULID, sess session.Permissions, TTL time.Duration) (session.ID, error)
	GetSession(ctx context.Context, id session.ID) (session.Session, error)
	DeleteSession(ctx context.Context, id session.ID) error
}

type UserStore

type UserStore interface {
	CreateUser(ctx context.Context, user scylla.User) error
	GetUsers(ctx context.Context) ([]scylla.User, error)
	GetUser(ctx context.Context, id ulid.ULID) (scylla.User, error)
	GetUserByEmail(ctx context.Context, email string) (scylla.User, error)
	DeleteUser(ctx context.Context, id ulid.ULID) error
}

type WebpushStore

type WebpushStore interface {
	GetWebpushKey(ctx context.Context) (scylla.KeyPair, error)
	RegisterWebpush(ctx context.Context, userID ulid.ULID, endpoint, auth, p256dh string) error
}

Directories

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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