Documentation
¶
Index ¶
- Constants
- type Person
- type PersonDirectory
- func (ds *PersonDirectory) CanInsert(r *http.Request) bool
- func (ds *PersonDirectory) Delete(personID string) (ok bool)
- func (ds *PersonDirectory) Insert(person *Person) (id string, err error)
- func (ds *PersonDirectory) List() []*Person
- func (ds *PersonDirectory) Lookup(personID string) (person *Person, ok bool)
- func (ds *PersonDirectory) LookupByEmail(email string) (person *Person, ok bool)
- func (ds *PersonDirectory) RandomPerson() *Person
- func (ds *PersonDirectory) Update(person *Person) (err error)
- type UnitedState
Constants ¶
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.
type PersonDirectory ¶
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%'