apiv1

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package apiv1 provides a JSON API for interacting with accounts.

This package can be imported to get an http.Handler that will provide access for retrieving Accounts, listing Accounts by their ProfileID, adding Accounts, and deleting Accounts.

The lockbox.dev/sessions package is used to authenticate a JWT bearer token for deleting Accounts, retrieving a specific Account, adding new Accounts to an existing profile, or listing Accounts associated with a profile. The bearer token's AccountID will be used as an Account's ID, and that Account's ProfileID must match the ProfileID of the Accounts being acted on or the profile Accounts are being listed for.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIv1

type APIv1 struct {
	accounts.Dependencies
	Log      *yall.Logger
	Sessions sessions.Dependencies
}

APIv1 holds all the information that we want to be available for all the functions in the API, things like our logging, metrics, and other telemetry.

func (APIv1) GetAuthToken

func (a APIv1) GetAuthToken(r *http.Request) (*sessions.AccessToken, *Response)

GetAuthToken returns the access token associated with the request, or a Response that should be rendered if there's an error.

func (APIv1) Server

func (a APIv1) Server(baseURL string) http.Handler

Server returns an http.Handler that will handle all the requests for v1 of the API. The baseURL should be set to whatever prefix the muxer matches to pass requests to the Handler; consider it the root path of v1 of the API.

type Account

type Account struct {
	ID             string    `json:"id"`
	ProfileID      string    `json:"profileID"`
	IsRegistration bool      `json:"isRegistration"`
	CreatedAt      time.Time `json:"createdAt"`
	LastSeenAt     time.Time `json:"lastSeenAt,omitempty"`
	LastUsedAt     time.Time `json:"lastUsedAt,omitempty"`
}

Account is the API representation of an Account. it dictates what the JSON representation of Accounts will be.

type Change

type Change struct {
	LastSeenAt *time.Time `json:"lastSeenAt,omitempty"`
	LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
}

Change is the API representation of a Change. It dictates what the JSON representation of Changes will be.

type Response

type Response struct {
	Accounts []Account          `json:"accounts,omitempty"`
	Errors   []api.RequestError `json:"errors,omitempty"`
	Status   int                `json:"-"`
}

Response is used to encode JSON responses; it is the global response format for all API responses.

Jump to

Keyboard shortcuts

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