Documentation ¶
Index ¶
- Constants
- Variables
- func CreateCreatedEvent(ctx context.Context, id int64, el EventLocation, c *CreatedContent) (eventID int64, err error)
- func CreateDevice(ctx context.Context, device *Device) (id int64, err error)
- func CreateEvent(ctx context.Context, id int64, el EventLocation, event *Event) (eventID int64, err error)
- func CreateModel(ctx context.Context, model *Model) (id int64, err error)
- func CreateModifiedEvent(ctx context.Context, id int64, el EventLocation, c *ModifiedContent) (eventID int64, err error)
- func CreateNoteEvent(ctx context.Context, id int64, el EventLocation, note string) (eventID int64, err error)
- func CreateUser(ctx context.Context, user *User) (id int64, err error)
- func CreateUserWithCredentials(ctx context.Context, email, password, name string) (id int64, err error)
- func UpdateDevice(ctx context.Context, device *Device) error
- func UpdateModel(ctx context.Context, model *Model) error
- func UpdateUser(ctx context.Context, user *User) error
- func ValidateString(field, value string, max int) error
- type CreatedContent
- type CreatedField
- type Device
- func QueryDevice(ctx context.Context, ...) ([]*Device, error)
- func ReadDevice(ctx context.Context, id int64, includeEvents bool) (*Device, error)
- func ReadDeviceBySerialNumber(ctx context.Context, serialNumber string, includeEvents bool) (*Device, error)
- func SimpleQueryDevice(ctx context.Context, search string) ([]*Device, error)
- type Error
- type ErrorType
- type Event
- type EventLocation
- type Location
- type Model
- type ModifiedContent
- type ModifiedField
- type NoteContent
- type Stats
- type StatsLocation
- type StatsModel
- type StatsStatus
- type Status
- type User
Constants ¶
const TransactionKey contextKey = 0
TransactionKey is the context key for the database transaction for a request
const UserKey contextKey = 1
UserKey is the context key for the user for a request
Variables ¶
var DeviceEventLocation = EventLocation{
Type: "Device",
Table: "device_log",
IDField: "device_id",
}
DeviceEventLocation is the EventLocation for the Device type
Functions ¶
func CreateCreatedEvent ¶
func CreateCreatedEvent(ctx context.Context, id int64, el EventLocation, c *CreatedContent) (eventID int64, err error)
CreateCreatedEvent creates a new Created Event for the given type, id, and content
func CreateDevice ¶
CreateDevice creates a new Device with the given fields (ID and Events are ignored and created) and returns its ID, or an error if one occurred
func CreateEvent ¶
func CreateEvent(ctx context.Context, id int64, el EventLocation, event *Event) (eventID int64, err error)
CreateEvent creates a new Event for the given type and id with the given fields (ID is ignored and created) and returns its ID or an error if one occurred
func CreateModel ¶
CreateModel creates a new Model with the given fields (ID and Events are ignored and created) and returns its ID, or an error if one occurred
func CreateModifiedEvent ¶
func CreateModifiedEvent(ctx context.Context, id int64, el EventLocation, c *ModifiedContent) (eventID int64, err error)
CreateModifiedEvent creates a new Modified Event for the given type, id, and content
func CreateNoteEvent ¶
func CreateNoteEvent(ctx context.Context, id int64, el EventLocation, note string) (eventID int64, err error)
CreateNoteEvent creates a new Note Event for the given type and id with the given note text
func CreateUser ¶
CreateUser creates a new User with the given fields (ID is ignored and created) and returns its ID, or an error if one occurred
func CreateUserWithCredentials ¶
func CreateUserWithCredentials(ctx context.Context, email, password, name string) (id int64, err error)
CreateUserWithCredentials creates a new User with the given information and returns it, or an error if one occurred
func UpdateDevice ¶
UpdateDevice updates the fields for the given Device (using the ID field, Events are ignored), or returns an error if one occurred
func UpdateModel ¶
UpdateModel updates the fields for the given Model (using the ID field, Events are ignored), or returns an error if one occurred
func UpdateUser ¶
UpdateUser updates the fields for the given User (using the ID field), or returns an error if one occurred
func ValidateString ¶
ValidateString returns an error if the given value is not within the parameters
Types ¶
type CreatedContent ¶
type CreatedContent struct {
Fields []*CreatedField `json:"fields"`
}
CreatedContent represents content for a created event
type CreatedField ¶
type CreatedField struct { Name string `json:"name"` Value interface{} `json:"value"` Model *Model `json:"_model,omitempty"` }
CreatedField represents a field for a CreatedContent. If Name is model_id, Model will be populated.
type Device ¶
type Device struct { ID int64 `json:"id"` SerialNumber string `json:"serial_number"` ModelID int64 `json:"model_id,omitempty"` Status Status `json:"status"` Location Location `json:"location"` Model *Model `json:"model,omitempty"` Events []*Event `json:"events,omitempty"` }
Device represents an inventoried device. ModelID is populated for Create, Read, and Update. Model is populated for Queries.
func QueryDevice ¶
func QueryDevice(ctx context.Context, serialNumber, manufacturer, model, status, location string) ([]*Device, error)
QueryDevice returns all Devices matching the given serial number, manufacturer, model, status, or location, or an error if one occurred.
func ReadDevice ¶
ReadDevice returns the Device with the given id, or an error if one occurred. If includeEvents is true the Events field will be populated
func ReadDeviceBySerialNumber ¶
func ReadDeviceBySerialNumber(ctx context.Context, serialNumber string, includeEvents bool) (*Device, error)
ReadDeviceBySerialNumber returns the Device with the given Serial Number, or an error if one occurred. If includeEvents is true the Events field will be populated
func SimpleQueryDevice ¶
SimpleQueryDevice returns all Devices matching the given search (searching all fields), or an error if one occurred.
type Event ¶
type Event struct { ID int64 `json:"-"` Date time.Time `json:"date"` UserID int64 `json:"user_id"` User *User `json:"_user,omitempty"` Type string `json:"type"` Content interface{} `json:"content"` }
Event represents an event that has happened. UserID should be used when creating and Event and User is used when reading and Event.
func ReadEvents ¶
ReadEvents returns the events for the given type and id, or an error if one occurred
type EventLocation ¶
EventLocation contains information needed to add events for the given type
type Location ¶
type Location string
Location is an allowed location
func ReadLocations ¶
ReadLocations returns all Locations, or an error if one occurred
type Model ¶
type Model struct { ID int64 `json:"id"` Manufacturer string `json:"manufacturer"` Model string `json:"model"` }
Model represents a device model
func QueryModel ¶
QueryModel returns all Models matching the given manufacturer and model or an error if one occurred.
type ModifiedContent ¶
type ModifiedContent struct {
Fields []*ModifiedField `json:"fields"`
}
ModifiedContent represents content for a modified event
type ModifiedField ¶
type ModifiedField struct { Name string `json:"name"` OldValue interface{} `json:"old_value"` OldModel *Model `json:"_old_model,omitempty"` NewValue interface{} `json:"new_value"` NewModel *Model `json:"_new_model,omitempty"` }
ModifiedField represents a field for a ModifiedContent. If Name is model_id, OldModel and NewModel will be populated.
type NoteContent ¶
type NoteContent struct {
Note string `json:"note"`
}
NoteContent represents content for a note event
type Stats ¶
type Stats struct { Locations []*StatsLocation `json:"locations"` Models []*StatsModel `json:"models"` Statuses []*StatsStatus `json:"statuses"` DeviceCount int `json:"device_count"` ModelCount int `json:"model_count"` LocationCount int `json:"location_count"` Devices []*Device `json:"devices"` }
Stats represents device statistics (top 10, etc)
type StatsLocation ¶
StatsLocation represents Location Stats
type StatsModel ¶
type StatsModel struct { ID int64 `json:"id"` Manufacturer string `json:"manufacturer"` Model string `json:"model"` Count int `json:"count"` }
StatsModel represents Model Stats
type StatsStatus ¶
StatsStatus represents Status Stats
type Status ¶
type Status string
Status is an allowed status
func ReadStatuses ¶
ReadStatuses returns all Statuses, or an error if one occurred
type User ¶
type User struct { ID int64 `json:"id"` Email string `json:"email"` Hash []byte `json:"-"` Name string `json:"name"` }
User represents an authencatable user
func ReadUserByEmail ¶
ReadUserByEmail returns the User with the given email, or an error if one occurred
func (*User) Authenticate ¶
Authenticate authenticates against the database with the given credentials and returns nil if success or error on failure
func (*User) ChangePassword ¶
ChangePassword updates the password hash to the given password