Species Methods - adampresley/swapi-go GitHub Wiki
The Species methods return information about the various types of species found in the Star Wars universe. Below are links to more information about the RESTful API, as well as documentation for the structures and each method.
type Species struct {
errors.Error
Name string `json:"name"`
Classification string `json:"classification"`
Designation string `json:"designation"`
AverageHeight string `json:"average_height"`
SkinColors string `json:"skin_colors"`
HairColors string `json:"hair_colors"`
EyeColors string `json:"eye_colors"`
AverageLifespan string `json:"average_lifespan"`
Homeworld string `json:"homeworld"`
People []string `json:"people"`
Films []string `json:"films"`
Created string `json:"created"`
Edited string `json:"edited"`
Url string `json:"url"`
}
type SpeciesCollection struct {
errors.Error
collection.SWAPIResultCollection
Results []Species `json:"results"`
}
Description: Returns a collection of Species structures in the form of a SpeciesCollection structure.
Returns: SpeciesCollection structure, HTTP status code, error
Example:
package main
import (
"log"
"github.com/adampresley/swapi-go/swapi"
)
func main() {
client := swapi.NewClient()
speciesCollection, status, err := client.GetAllSpecies()
if err != nil {
log.Fatalf("Cannot get species: %s", err.Error())
}
if status != 200 {
log.Println("HTTP error with message", result.ErrorMessage)
}
/*
* Iterate over the results and do something useful
*/
for _, species := range speciesCollection.Results {
// useful
}
}
Description: Returns a single Species structure by ID.
Returns: Species structure, HTTP status code, error
Example:
package main
import (
"log"
"github.com/adampresley/swapi-go/swapi"
)
func main() {
client := swapi.NewClient()
species, status, err := client.GetSpeciesById(1)
if err != nil {
log.Fatalf("Cannot get species: %s", err.Error())
}
if status != 200 {
log.Println("HTTP error with message", result.ErrorMessage)
}
// Do something useful with this species
}