storage

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MaxDirectoryRecords = 20

MaxDirectoryRecords is the maximum number of persons allowed in the directory.

Variables

This section is empty.

Functions

This section is empty.

Types

type Person

type Person struct {
	ID        string
	FirstName string
	LastName  string
	Email     string
	Phone     string
	Birthday  time.Time
	Address1  string
	Address2  string
	City      string
	State     string
	Zip       string
}

Person keeps personal information about a person. All directories are scoped to a single session (see shared/session.go); persons stored in one session's directory are never visible to another session.

func (*Person) FullName

func (p *Person) FullName() string

FullName combines the person's first and last names.

type PersonDirectory

type PersonDirectory struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PersonDirectory keeps a list of persons.

func (*PersonDirectory) CanInsert

func (ds *PersonDirectory) CanInsert(r *http.Request) bool

CanInsert indicates if there is room in the directory to add more persons.

func (*PersonDirectory) Delete

func (ds *PersonDirectory) Delete(personID string) (ok bool)

Delete removes the data of a person from the directory.

func (*PersonDirectory) Insert

func (ds *PersonDirectory) Insert(person *Person) (id string, err error)

Insert add a person to the directory. If a person with the same email address already exists, a new record is not created.

func (*PersonDirectory) List

func (ds *PersonDirectory) List() []*Person

List returns all persons in the directory. The data returned is a fresh copy so it is thread-safe.

func (*PersonDirectory) Lookup

func (ds *PersonDirectory) Lookup(personID string) (person *Person, ok bool)

Lookup returns a person by ID. The data returned is a fresh copy so it is thread-safe.

func (*PersonDirectory) LookupByEmail

func (ds *PersonDirectory) LookupByEmail(email string) (person *Person, ok bool)

Lookup returns a person by email. The data returned is a fresh copy so it is thread-safe.

func (*PersonDirectory) RandomPerson

func (ds *PersonDirectory) RandomPerson() *Person

func (*PersonDirectory) Update

func (ds *PersonDirectory) Update(person *Person) (err error)

Update updates the data of a person in the directory.

type UnitedState

type UnitedState struct {
	Abbrev            string
	Name              string
	Population        int
	Land              float64
	GDP               int
	PopulationDensity float64
	GDPPerCapita      float64
}

UnitedState is one of the 50 states of the USA.

func USLookup

func USLookup(abbrev string) (*UnitedState, bool, error)

USLookup performs a query to the states data source to fetch one record. This is analogous to a query to a database:

SELECT * FROM States WHERE Abbrev='abbrev'

func USQuery

func USQuery(query string, sortOrder string, rowFrom int, rowTo int) (states []*UnitedState, totalRecords int, err error)

USQuery performs a query to the states data source to fetch, filter, sort and slice the records that match the user's request. This is analogous to a query to a database:

SELECT * FROM States
WHERE Name LIKE '%query%' OR Abbrev LIKE '%query%'
ORDER BY sortOrder
LIMIT (rowTo-rowFrom) OFFSET rowFrom

If the total number of records matching the query can be discerned (as is in this case), the table paginator is able to display the total number of pages. When a database is involved, this often necessitates another query.

SELECT COUNT(*) FROM States
WHERE Name LIKE '%query%' OR Abbrev LIKE '%query%'

Jump to

Keyboard shortcuts

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