httpapi

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const TransactionKey contextKey = 0

TransactionKey is the context key for the database transaction for a request

View Source
const UserKey contextKey = 1

UserKey is the context key for the user for a request

Variables

This section is empty.

Functions

func NewRouter

func NewRouter(w io.Writer, s SessionStore, db *sql.DB) http.Handler

NewRouter returns an HTTP router for the HTTP API

Types

type AuthenticateRequest

type AuthenticateRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

AuthenticateRequest is an email/password authentication request

type AuthenticateResponse

type AuthenticateResponse struct {
	SessionKey string    `json:"session_key"`
	User       *api.User `json:"user"`
}

AuthenticateResponse is a successful authentication response including the session key and User

type ChangeUserPasswordRequest

type ChangeUserPasswordRequest struct {
	OldPassword string `json:"old_password"`
	NewPassword string `json:"new_password"`
}

ChangeUserPasswordRequest is a request to change a User's password

type CreateDeviceRequest

type CreateDeviceRequest struct {
	Device *api.Device `json:"device"`
	Note   string      `json:"note"`
}

CreateDeviceRequest is a Device Create and Note Create request combined

type CreateUserRequest

type CreateUserRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
	Name     string `json:"name"`
}

CreateUserRequest is a request to create a new User

type ErrorResponse

type ErrorResponse struct {
	Code        int    `json:"code"`
	Error       string `json:"error"`
	DuplicateID int64  `json:"duplicate_id,omitempty"`
}

ErrorResponse represents an HTTP error. If the error is 409 Conflict, the DuplicateID field will be populated.

type MemorySessionStore

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

MemorySessionStore represents a SessionStore that uses an in-memory map

func NewMemorySessionStore

func NewMemorySessionStore(duration time.Duration) *MemorySessionStore

NewMemorySessionStore returns a new MemorySessionStore with the given expiration duration.

func (*MemorySessionStore) Check

func (m *MemorySessionStore) Check(sessionID string) (session *Session, err error)

Check returns whether or not sessionID is a valid session. If sessionID is not valid, session will be nil. err will always be nil.

func (*MemorySessionStore) Create

func (m *MemorySessionStore) Create(userID int64) (sessionID string, err error)

Create returns a new sessionID with the given User id. err will always be nil.

type NoteRequest

type NoteRequest struct {
	Note string `json:"note"`
}

NoteRequest is a note encapsulated in a JSON object

type QueryDeviceResponse

type QueryDeviceResponse struct {
	Devices []*api.Device `json:"devices"`
}

QueryDeviceResponse contains a list of Models

type QueryModelResponse

type QueryModelResponse struct {
	Models []*api.Model `json:"models"`
}

QueryModelResponse contains a list of Models

type ReadLocationsResponse

type ReadLocationsResponse struct {
	Locations []api.Location `json:"locations"`
}

ReadLocationsResponse contains a list of allowed Locations

type ReadStatusesResponse

type ReadStatusesResponse struct {
	Statuses []api.Status `json:"statuses"`
}

ReadStatusesResponse contains a list of allowed Statuses

type Session

type Session struct {
	UserID  int64
	Expires time.Time
}

Session represents a login session

type SessionStore

type SessionStore interface {
	//Create returns a new sessionID with the given User id. If the backend malfunctions,
	//sessionID will be an empty string and err will be non-nil.
	Create(userID int64) (sessionID string, err error)

	//Check returns whether or not sessionID is a valid session.
	//If sessionID is not valid, session will be nil.
	//If the backend malfunctions, session will be nil and err will be non-nil.
	Check(sessionID string) (session *Session, err error)
}

SessionStore is an interface to an arbitrary session backend.

Jump to

Keyboard shortcuts

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