Documentation
¶
Index ¶
- func DataMiddleware(db *DBLoader) func(http.Handler) http.Handler
- type DBLoader
- type DeviceLoader
- func (l *DeviceLoader) Clear(key string)
- func (l *DeviceLoader) Load(key string) (*models.Device, error)
- func (l *DeviceLoader) LoadAll(keys []string) ([]*models.Device, []error)
- func (l *DeviceLoader) LoadAllThunk(keys []string) func() ([]*models.Device, []error)
- func (l *DeviceLoader) LoadThunk(key string) func() (*models.Device, error)
- func (l *DeviceLoader) Prime(key string, value *models.Device) bool
- type DeviceLoaderConfig
- type RoomLoader
- func (l *RoomLoader) Clear(key string)
- func (l *RoomLoader) Load(key string) (*models.Room, error)
- func (l *RoomLoader) LoadAll(keys []string) ([]*models.Room, []error)
- func (l *RoomLoader) LoadAllThunk(keys []string) func() ([]*models.Room, []error)
- func (l *RoomLoader) LoadThunk(key string) func() (*models.Room, error)
- func (l *RoomLoader) Prime(key string, value *models.Room) bool
- type RoomLoaderConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DBLoader ¶
type DBLoader struct { DeviceRepo mongodb.DeviceRepo RoomRepo mongodb.RoomRepo }
DBLoader for middleware
type DeviceLoader ¶
type DeviceLoader struct {
// contains filtered or unexported fields
}
DeviceLoader batches and caches requests
func GetDeviceLoader ¶
func GetDeviceLoader(ctx context.Context) *DeviceLoader
GetDeviceLoader get device dataloader
func NewDeviceLoader ¶
func NewDeviceLoader(config DeviceLoaderConfig) *DeviceLoader
NewDeviceLoader creates a new DeviceLoader given a fetch, wait, and maxBatch
func (*DeviceLoader) Clear ¶
func (l *DeviceLoader) Clear(key string)
Clear the value at key from the cache, if it exists
func (*DeviceLoader) Load ¶
func (l *DeviceLoader) Load(key string) (*models.Device, error)
Load a Device by key, batching and caching will be applied automatically
func (*DeviceLoader) LoadAll ¶
func (l *DeviceLoader) LoadAll(keys []string) ([]*models.Device, []error)
LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured
func (*DeviceLoader) LoadAllThunk ¶
func (l *DeviceLoader) LoadAllThunk(keys []string) func() ([]*models.Device, []error)
LoadAllThunk returns a function that when called will block waiting for a Devices. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.
func (*DeviceLoader) LoadThunk ¶
func (l *DeviceLoader) LoadThunk(key string) func() (*models.Device, error)
LoadThunk returns a function that when called will block waiting for a Device. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.
func (*DeviceLoader) Prime ¶
func (l *DeviceLoader) Prime(key string, value *models.Device) bool
Prime the cache with the provided key and value. If the key already exists, no change is made and false is returned. (To forcefully prime the cache, clear the key first with loader.clear(key).prime(key, value).)
type DeviceLoaderConfig ¶
type DeviceLoaderConfig struct { // Fetch is a method that provides the data for the loader Fetch func(keys []string) ([]*models.Device, []error) // Wait is how long wait before sending a batch Wait time.Duration // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit MaxBatch int }
DeviceLoaderConfig captures the config to create a new DeviceLoader
type RoomLoader ¶
type RoomLoader struct {
// contains filtered or unexported fields
}
RoomLoader batches and caches requests
func GetRoomLoader ¶
func GetRoomLoader(ctx context.Context) *RoomLoader
GetRoomLoader get device dataloader
func NewRoomLoader ¶
func NewRoomLoader(config RoomLoaderConfig) *RoomLoader
NewRoomLoader creates a new RoomLoader given a fetch, wait, and maxBatch
func (*RoomLoader) Clear ¶
func (l *RoomLoader) Clear(key string)
Clear the value at key from the cache, if it exists
func (*RoomLoader) Load ¶
func (l *RoomLoader) Load(key string) (*models.Room, error)
Load a Room by key, batching and caching will be applied automatically
func (*RoomLoader) LoadAll ¶
func (l *RoomLoader) LoadAll(keys []string) ([]*models.Room, []error)
LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured
func (*RoomLoader) LoadAllThunk ¶
func (l *RoomLoader) LoadAllThunk(keys []string) func() ([]*models.Room, []error)
LoadAllThunk returns a function that when called will block waiting for a Rooms. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.
func (*RoomLoader) LoadThunk ¶
func (l *RoomLoader) LoadThunk(key string) func() (*models.Room, error)
LoadThunk returns a function that when called will block waiting for a Room. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.
func (*RoomLoader) Prime ¶
func (l *RoomLoader) Prime(key string, value *models.Room) bool
Prime the cache with the provided key and value. If the key already exists, no change is made and false is returned. (To forcefully prime the cache, clear the key first with loader.clear(key).prime(key, value).)
type RoomLoaderConfig ¶
type RoomLoaderConfig struct { // Fetch is a method that provides the data for the loader Fetch func(keys []string) ([]*models.Room, []error) // Wait is how long wait before sending a batch Wait time.Duration // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit MaxBatch int }
RoomLoaderConfig captures the config to create a new RoomLoader