Documentation
¶
Index ¶
- func CheckActivity(a *Activity) error
- func ConfigToModel(config Config) *models.Config
- func CopyStore(from, to *Store)
- func MakeClaims(mp *models.Permission) permission.Token
- func NewStreamsFromModel(modelStreams []*models.Stream) map[string]*Stream
- func SingleStreamToModel(s *Stream) *models.Stream
- func SingleUIToModel(u *UI) *models.UserInterface
- func StreamsToModel(streams map[string]*Stream) []*models.Stream
- func UIsToModel(uis []*UI) []*models.UserInterface
- type Activity
- func (a *Activity) AddID() string
- func (a *Activity) AddStream(key string, stream *Stream)
- func (a *Activity) AddUI(ui *UI)
- func (a *Activity) ConvertToModel() *models.Activity
- func (a *Activity) GetID() string
- func (a *Activity) SetID(id string)
- func (a *Activity) WithID(id string) *Activity
- func (a *Activity) WithNewRandomID() *Activity
- type Config
- type Description
- func (d *Description) ConvertToModel() *models.Description
- func (d *Description) SetFurther(item string)
- func (d *Description) SetID(item string)
- func (d *Description) SetImage(item string)
- func (d *Description) SetLong(item string)
- func (d *Description) SetShort(item string)
- func (d *Description) SetThumb(item string)
- func (d *Description) SetType(item string)
- func (d *Description) WithID(id string) *Description
- type DisplayInfo
- type Group
- func (g *Group) AddPool(pool *Pool)
- func (g *Group) AddPools(pools []*Pool)
- func (g *Group) DeletePool(pool *Pool)
- func (g *Group) GetID() string
- func (g *Group) GetPoolIDs() []string
- func (g *Group) GetPools() []*Pool
- func (g *Group) SetNewRandomID() *Group
- func (g *Group) SetPools(pools []*Pool)
- func (g *Group) WithID(id string) *Group
- func (g *Group) WithPool(pool *Pool) *Group
- func (g *Group) WithPools(pools []*Pool) *Group
- type Pool
- func (p *Pool) ActivityExists(id string) bool
- func (p *Pool) ActivityInUse(id string) bool
- func (p *Pool) ActivityNextAvailableTime(id string) (int64, error)
- func (p *Pool) ActivityRequest(duration uint64, id string) error
- func (p *Pool) ActivityRequestAny(duration uint64) (string, error)
- func (p *Pool) ActivityWaitAny() (uint64, error)
- func (p *Pool) ActivityWaitDuration(duration uint64) (uint64, error)
- func (p *Pool) AddActivity(activity *Activity) error
- func (p *Pool) CountAvailable() int
- func (p *Pool) CountInUse() int
- func (p *Pool) DeleteActivity(activity *Activity)
- func (p *Pool) GetActivityByID(id string) (*Activity, error)
- func (p *Pool) GetActivityIDs() []string
- func (p *Pool) GetID() string
- func (p *Pool) GetMaxSession() uint64
- func (p *Pool) GetMinSession() uint64
- func (p *Pool) RemoveStaleEntries()
- func (p *Pool) SetMaxSesssion(duration uint64)
- func (p *Pool) SetMinSesssion(duration uint64)
- func (p *Pool) WithDescription(d Description) *Pool
- func (p *Pool) WithID(id string) *Pool
- func (p *Pool) WithMaxSesssion(duration uint64) *Pool
- func (p *Pool) WithMinSesssion(duration uint64) *Pool
- func (p *Pool) WithNow(now func() int64) *Pool
- type Store
- func (p *Store) AddGroup(group *Group)
- func (p *Store) AddPool(pool *Pool)
- func (p *Store) DeleteGroup(group *Group)
- func (p *Store) DeletePool(pool *Pool)
- func (p *Store) ExportAll() ([]byte, error)
- func (p *Store) GetAllGroupsCount() int
- func (p *Store) GetAllPoolCount() int
- func (p *Store) GetAllPoolIDs() []string
- func (p *Store) GetAllPools() []*Pool
- func (p *Store) GetAvailableActivitiesCount() int
- func (p *Store) GetGroupByID(id string) (*Group, error)
- func (p *Store) GetGroupsByName(name string) ([]*Group, error)
- func (p *Store) GetGroupsByNamePrefix(prefix string) ([]*Group, error)
- func (p *Store) GetPoolByID(id string) (*Pool, error)
- func (p *Store) GetPoolsByName(name string) ([]*Pool, error)
- func (p *Store) GetPoolsByNamePrefix(prefix string) ([]*Pool, error)
- func (p *Store) GetSecret() []byte
- func (p *Store) GetTime() int64
- func (p *Store) PostImportEssential()
- func (p *Store) PostImportSetNow(now func() int64)
- func (p *Store) Reset()
- func (p *Store) SetSecret(secret string)
- func (p *Store) WithBookingTokenDuration(duration int64) *Store
- func (p *Store) WithNow(now func() int64) *Store
- func (p *Store) WithSecret(secret string) *Store
- type Stream
- type UI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckActivity ¶
CheckActivity throws an error if any essential elements are missing from an Activity
func ConfigToModel ¶
ConfigToModel returns a pointer to a Config represented in the API's model
func CopyStore ¶
func CopyStore(from, to *Store)
CopyStore copys pools, groups, secret, booking token duration and now function from one Store to another
func MakeClaims ¶
func MakeClaims(mp *models.Permission) permission.Token
MakeClaims creates claims from the API's model.Permission
func NewStreamsFromModel ¶
NewStreamsFromModel returns a map of streams from the API's model representation
func SingleStreamToModel ¶
SingleStreamToModel returns a pointer to a Stream represented in the API's model
func SingleUIToModel ¶
func SingleUIToModel(u *UI) *models.UserInterface
SingleUIToModel returns a pointer to a UI represented in the API's model
func StreamsToModel ¶
StreamsToModel returns an array of pointers to Streams represented in the API's model
func UIsToModel ¶
func UIsToModel(uis []*UI) []*models.UserInterface
UIsToModel returns an array of pointers to UI represented in the API's model
Types ¶
type Activity ¶
type Activity struct {
*sync.RWMutex `json:"-"`
Config Config `json:"config"`
Description `json:"description"`
ExpiresAt int64 `json:"exp"`
Streams map[string]*Stream `json:"streams"`
UI []*UI `json:"ui"`
}
Activity represents an individual activity that can be booked
func NewActivity ¶
NewActivity returns a pointer to an activity that is populated with a name and expiry datetime.
func NewActivityFromModel ¶
NewActivityFromModel creates a new Activity from the API's model representation
func (*Activity) ConvertToModel ¶
ConvertToModel returns a pointer to an Activity represented in the API's model
func (*Activity) WithNewRandomID ¶
WithNewRandomID adds a new random ID to the activity
type Config ¶
type Config struct {
URL string `json:"url"`
}
Config represents a UI configuration file URL
func NewConfigFromModel ¶
NewConfigFromModel returns a pointer to a Config converted from the API's model
type Description ¶
type Description struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
DisplayInfo
}
Description represents an Activity Description
func NewDescription ¶
func NewDescription(name string) *Description
NewDescription returns a pointer to a Description with given name and randomly generated UUID as ID
func NewDescriptionFromModel ¶
func NewDescriptionFromModel(md *models.Description) *Description
NewDescriptionFromModel returns a pointer to a Description converted from the API's model
func (*Description) ConvertToModel ¶
func (d *Description) ConvertToModel() *models.Description
ConvertToModel returns a pointer to the Description represented in the API's model
func (*Description) SetFurther ¶
func (d *Description) SetFurther(item string)
SetFurther sets the URL for further information (in string format)
func (*Description) SetID ¶
func (d *Description) SetID(item string)
SetID sets the ID of the Description
func (*Description) SetImage ¶
func (d *Description) SetImage(item string)
SetImage sets the URL of the large/main image of the activity
func (*Description) SetLong ¶
func (d *Description) SetLong(item string)
SetLong sets the long description field in the Description
func (*Description) SetShort ¶
func (d *Description) SetShort(item string)
SetShort sets the short description field in the Descriptiom
func (*Description) SetThumb ¶
func (d *Description) SetThumb(item string)
SetThumb sets the URL of the thumbnail image of the activity
func (*Description) SetType ¶
func (d *Description) SetType(item string)
SetType sets the Type field in the Description
func (*Description) WithID ¶
func (d *Description) WithID(id string) *Description
WithID sets the ID of the Description
type DisplayInfo ¶
type DisplayInfo struct {
Short string `json:"short,omitempty"`
Long string `json:"long,omitempty"`
Further string `json:"further,omitempty"`
Thumb string `json:"thumb,omitempty"`
Image string `json:"image,omitempty"`
}
DisplayInfo represents information about an Activity that is displayed to users
type Group ¶
type Group struct {
*sync.RWMutex `json:"-" yaml:"-"`
Description `json:"description"`
Pools []*Pool `json:"pools"`
}
Group represents a group of Pools
func NewGroupFromModel ¶
NewGroupFromModel returns a pointer to Group created from the API's model
func (*Group) AddPool ¶
AddPool adds the pool to the existing list of pools, all existing pools are retained
func (*Group) DeletePool ¶
DeletePool removes a single pool from the Group, if it was present
func (*Group) GetPoolIDs ¶
GetPoolIDs returns an array of all Pool IDs in the Group
func (*Group) SetNewRandomID ¶
SetNewRandomID sets a random UUID as the Group ID
type Pool ¶
type Pool struct {
*sync.RWMutex `json:"-" yaml:"-"`
Description `json:"description"`
Activities map[string]*Activity `json:"activities"`
Available map[string]int64 `json:"available"`
InUse map[string]int64 `json:"inUse"`
MinSession uint64 `json:"minSession"`
MaxSession uint64 `json:"maxSession"`
Now func() int64 `json:"-" yaml:"-"`
}
Pool represents the booking status of the activities in a pool Note that each pool can have a different minSession / MaxSession duration but that users are limited to fixed maximum number of sessions they can book across the system to prevent users with access with more pools booking even more experiments simultaneously.
func (*Pool) ActivityExists ¶
ActivityExists checks whether an activity of the given ID exists in the pool (returns true if exists)
func (*Pool) ActivityInUse ¶
ActivityInUse checks whether an activity with the given ID is currently in use (returns true if in use)
func (*Pool) ActivityNextAvailableTime ¶
ActivityNextAvailableTime returns the time that the activity of the given ID will be next available
func (*Pool) ActivityRequest ¶
ActivityRequest marks activity with given ID as being 'in use' until the time requested, but throws an error if the ID does not exist or is in-use already
func (*Pool) ActivityRequestAny ¶
ActivityRequestAny returns the ID of a free activity that is available for the requested duration, and marks the activity as 'in use' until the time requested or throws an error if no free activities.
func (*Pool) ActivityWaitAny ¶
ActivityWaitAny returns the wait time for an activity to come free that can be booked for one second or more.
func (*Pool) ActivityWaitDuration ¶
ActivityWaitDuration returns the wait time for an activity to come free that can be booked for the specified ActivityWaitDuration this covers the case when an activity might come free, but have only a short time left before it expires from the manifest
func (*Pool) AddActivity ¶
AddActivity adds a single Activity to a pool
func (*Pool) CountAvailable ¶
CountAvailable returns the number of activities available to book in the pool now
func (*Pool) CountInUse ¶
CountInUse returns the number of activities in use now
func (*Pool) DeleteActivity ¶
DeleteActivity removes a single Activity from the Pool
func (*Pool) GetActivityByID ¶
GetActivityByID returns a pointer to the Activity of the given ID
func (*Pool) GetActivityIDs ¶
GetActivityIDs returns an array containing the IDs of all activities in the Pool
func (*Pool) GetMaxSession ¶
GetMaxSession returns the maximum bookable session duration in seconds
func (*Pool) GetMinSession ¶
GetMinSession returns the minimum bookable session duration in seconds
func (*Pool) RemoveStaleEntries ¶
func (p *Pool) RemoveStaleEntries()
RemoveStaleEntries tidies up any entries in the InUse list that have since expired
func (*Pool) SetMaxSesssion ¶
SetMaxSesssion sets the maximum session duration that can be booked by a user usually intended to match the maximum sustained session expected of a user and not set so long that a user can tie up equipment unduly (there is no cancel at the present time)
func (*Pool) SetMinSesssion ¶
SetMinSesssion sets the minimum session duration that can be booked the minimum bookable duration is usually set by the checking routines run by the system
func (*Pool) WithDescription ¶
func (p *Pool) WithDescription(d Description) *Pool
WithDescription adds a description to the Pool
func (*Pool) WithMaxSesssion ¶
WithMaxSesssion sets the maximum session duration that can be booked by a user usually intended to match the maximum sustained session expected of a user and not set so long that a user can tie up equipment unduly (there is no cancel at the present time)
func (*Pool) WithMinSesssion ¶
WithMinSesssion sets the minimum session duration that can be booked the minimum bookable duration is usually set by the checking routines run by the system
type Store ¶
type Store struct {
*sync.RWMutex `json:"-" yaml:"-"`
// Groups represent non-exclusive combinations of pools
Groups map[string]*Group `json:"groups"`
// Pools maps all pools in the store
Pools map[string]*Pool `json:"pools"`
// Secret for generating tokens - assume one PoolStore per relay
Secret []byte `json:"secret"`
// How long to grant booking tokens for
BookingTokenDuration int64 `json:"bookingTokenDuration"`
// Now is a function for getting the time - useful for mocking in test
Now func() int64 `json:"-" yaml:"-"`
}
Store represents Activities stored according to Pool and Group
func ImportAll ¶
ImportAll imports a Store from a serialised JSON representation in []byte format It creates all necessary mutexes so the store can operate properly after the import
func (*Store) DeleteGroup ¶
DeleteGroup removes a group from the store
func (*Store) DeletePool ¶
DeletePool removes a pool from the store
func (*Store) ExportAll ¶
ExportAll marshalls the Store to JSON and returns the []byte representation note that elements such as mutexes cannot be serialised and are omitted
func (*Store) GetAllGroupsCount ¶
GetAllGroupsCount returns a count of how many groups there are in the store
func (*Store) GetAllPoolCount ¶
GetAllPoolCount returns a count of how many pools are in the store
func (*Store) GetAllPoolIDs ¶
GetAllPoolIDs returns an array containing all the IDs of pools in the store
func (*Store) GetAllPools ¶
GetAllPools returns all pools in the Store
func (*Store) GetAvailableActivitiesCount ¶
GetAvailableActivitiesCount returns a count of how many activities are available
func (*Store) GetGroupByID ¶
GetGroupByID returns a pointer to the Group with the given ID, or an error
func (*Store) GetGroupsByName ¶
GetGroupsByName returns all groups with the given name
func (*Store) GetGroupsByNamePrefix ¶
GetGroupsByNamePrefix returns groups with a given string at the start of their name, or an error
func (*Store) GetPoolByID ¶
GetPoolByID returns a pointer to a Pool with the given ID, or an error
func (*Store) GetPoolsByName ¶
GetPoolsByName returns all pools with a given name
func (*Store) GetPoolsByNamePrefix ¶
GetPoolsByNamePrefix returns all pools with names starting with a given string
func (*Store) GetTime ¶
GetTime allows flexibility in choosing clock source default is internal clock of the server
func (*Store) PostImportEssential ¶
func (p *Store) PostImportEssential()
PostImportEssential sets up mutexes and Now() functions
func (*Store) PostImportSetNow ¶
PostImportSetNow applies a custom Now() func to the poolstore and all pools - useful for mocking time in tests which involve import/export
func (*Store) Reset ¶
func (p *Store) Reset()
Reset removes all pools and groups but does not change min/max session durations
func (*Store) SetSecret ¶
SetSecret sets the secret used to check token validity and sign tokens for streaming
func (*Store) WithBookingTokenDuration ¶
WithBookingTokenDuration sets the duration for which booking tokens are valid
func (*Store) WithNow ¶
WithNow sets the function that returns the datetime in seconds at the current time (useful for testing)
func (*Store) WithSecret ¶
WithSecret sets the secret used by the booking store
type Stream ¶
type Stream struct {
*sync.RWMutex `json:"-"`
// For is the key in the UI's URL in which the client puts
// the relay (wss) address and code after getting them
// from the relay
For string `json:"for,omitempty"`
// URL of the relay access point for this stream
URL string `json:"url"`
// signed bearer token for accessing the stream
// submit token in the header
Token string `json:"token,omitempty"`
// Verb is the HTTP method, typically post
Verb string `json:"verb,omitempty"`
// Permission is a prototype for the permission token that the booking system
// generates and puts into the Token field
Permission permission.Token `json:"permission,omitempty"`
}
Stream represents a data or video stream from a relay typically accessed via POST with bearer token
func NewSingleStreamFromModel ¶
NewSingleStreamFromModel returns a pointer to a Stream created from the API's model representation
func (*Stream) GetPermission ¶
func (s *Stream) GetPermission() permission.Token
GetPermission returns the permission (token) of the Stream
func (*Stream) SetPermission ¶
func (s *Stream) SetPermission(p permission.Token)
SetPermission sets the permission (token) for the Stream
func (*Stream) WithPermission ¶
func (s *Stream) WithPermission(p permission.Token) *Stream
WithPermission adds a permission to the Stream
type UI ¶
type UI struct {
// URL with moustache {{key}} templating for stream connections
Description `json:"description"`
URL string `json:"url"`
StreamsRequired []string `json:"streamsRequired"`
}
UI represents a UI that can be used with an Activity
func NewSingleUIFromModel ¶
func NewSingleUIFromModel(mui *models.UserInterface) *UI
NewSingleUIFromModel returns a pointer to a UI created from the API's model representation
func NewUIsFromModel ¶
func NewUIsFromModel(modelUIs []*models.UserInterface) []*UI
NewUIsFromModel creates an array of pointers to UI from the API's model representation
func (*UI) WithDescription ¶
func (u *UI) WithDescription(d Description) *UI
WithDescription adds a description to the UI
func (*UI) WithStreamsRequired ¶
WithStreamsRequired adds required streams to the UI