race

package
v0.0.0-...-24e094a Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("race: resource could not be located")
)

Common errors that you will likely want to account for in your code. Any other errors are wrapped with context via the github.com/pkg/errors package and returned but are harder to use an if/switch to match.

Functions

func Spend

func Spend(us interface {
	Find(int) (*User, error)
	Update(*User) error
}, userID int, amount int) error

Types

type User

type User struct {
	ID      int
	Name    string
	Email   string
	Balance int
}

User is an example user model. This typically wouldn't be defined in this package but is done here for simplicity.

type UserStore

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

UserStore is used to interact with our user store.

func (*UserStore) Create

func (us *UserStore) Create(user *User) error

Create will create a new user in the DB using the provided user and will update the ID of the provided user. If there is an error it will be wrapped and returned.

func (*UserStore) Delete

func (us *UserStore) Delete(id int) error

Delete will delete a user form the DB. If there is an error it will be wrapped and returned.

func (*UserStore) Find

func (us *UserStore) Find(id int) (*User, error)

Find will retrieve a user with the provided ID or return ErrNotFount if the user isn't located. Other errors are wrapped with context but are otherwise wrapped as-is.

func (*UserStore) Update

func (us *UserStore) Update(user *User) error

Update will update a user in the DB with the provided info.

Jump to

Keyboard shortcuts

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