-
Notifications
You must be signed in to change notification settings - Fork 0
/
species.go
30 lines (23 loc) · 802 Bytes
/
species.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"errors"
"github.com/jeroenrinzema/universal-name-translator/stapi"
)
// ErrNoSpecies is returned when no species are found for the given character
var ErrNoSpecies = errors.New("given character is not part of any species")
// LookupCharacterSpecies attempts to look up the species as a string of the given character.
// If a character is part of multiple species all species are joined and seperated by a comma
func LookupCharacterSpecies(name string) (result stapi.CharacterSpecies, err error) {
character, err := stapi.CharacterSearch(name)
if err != nil {
return nil, err
}
bio, err := stapi.CharacterBio(character.UID)
if err != nil {
return nil, err
}
if len(bio.CharacterSpecies) == 0 {
return nil, ErrNoSpecies
}
return bio.CharacterSpecies, nil
}