Skip to content

Instantly share code, notes, and snippets.

@mkock
Last active January 19, 2020 06:16
Show Gist options
  • Select an option

  • Save mkock/81776ce725d7962aa15c42626363dcd2 to your computer and use it in GitHub Desktop.

Select an option

Save mkock/81776ce725d7962aa15c42626363dcd2 to your computer and use it in GitHub Desktop.
Lookup functions before refactoring
// FindPlayerByID returns the player with the given ID, if exists.
// Otherwise, an empty Player is returned.
func FindPlayerByID(ID uint32) Player {
if p, ok := playerIDMap[ID]; ok {
return p
}
return Player{}
}
// FindPlayerByHandle returns the player with the given Handle,
// if exists. Otherwise, an empty Player is returned.
func FindPlayerByHandle(handle string) Player {
if p, ok := playerHandleMap[handle]; ok {
return p
}
return Player{}
}
// FindPlayerByCountry returns all players within the given country,
// if exists. Otherwise, an empty slice is returned.
func FindPlayerByCountry(code string) []Player {
if ps, ok := playerCountryMap[code]; ok {
return ps
}
return []Player{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment