loader

package
v0.0.0-...-c72a9d5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadUser

func LoadUser(ctx context.Context, id uuid.UUID) (model.User, error)

Types

type Collection

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

Collection holds an internal lookup of initialized batch data load functions.

func Initialize

func Initialize() Collection

Initialize a lookup map of context keys to batch functions.

When Attach is called on the Collection, the batch functions are used to create new dataloader instances. The instances are attached to the request context at the provided keys.

The keys are then used to extract the dataloader instances from the request context.

func (Collection) Attach

func (c Collection) Attach(ctx context.Context) context.Context

Attach creates new instances of dataloader.Loader and attaches the instances on the request context. We do this because the dataloader has an in-memory cache that is scoped to the request.

type UserResult

type UserResult struct {
	User  model.User
	Error error
}

UserResult is the (data, error) pair result of loading a specific key.

type UserResults

type UserResults []UserResult

UserResults is a named type, so methods can be attached to []UserResult.

func LoadUsers

func LoadUsers(ctx context.Context, ids []string) (UserResults, error)

func (UserResults) WithoutErrors

func (results UserResults) WithoutErrors() []model.User

WithoutErrors filters any result pairs with non-nil errors.

Jump to

Keyboard shortcuts

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