People Methods - adampresley/swapi-go GitHub Wiki
The People methods return information about characters 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 People struct {
errors.Error
BirthYear string `json:"birth_year"`
EyeColor string `json:"eye_color"`
Films []string `json:"films"`
Gender string `json:"gender"`
HairColor string `json:"hair_color"`
Height string `json:"height"`
Homeworld string `json:"homeworld"`
Mass string `json:"mass"`
Name string `json:"name"`
SkinColor string `json:"skin_color"`
Created string `json:"created"`
Edited string `json:"edited"`
Species []string `json:"species"`
Starships []string `json:"starships"`
Url string `json:"url"`
Vehicles []string `json:"vehicles"`
}
type PeopleCollection struct {
errors.Error
collection.SWAPIResultCollection
Results []People `json:"results"`
}
Description: Returns a collection of People structures in the form of a PeopleCollection structure.
Returns: PeopleCollection structure, HTTP status code, error
Example:
package main
import (
"log"
"github.com/adampresley/swapi-go/swapi"
)
func main() {
client := swapi.NewClient()
people, status, err := client.GetAllPeople()
if err != nil {
log.Fatalf("Cannot get people: %s", err.Error())
}
if status != 200 {
log.Println("HTTP error with message", result.ErrorMessage)
}
/*
* Iterate over the results and do something useful
*/
for _, person := range people.Results {
// useful
}
}
Description: Returns a single People structure by ID.
Returns: People structure, HTTP status code, error
Example:
package main
import (
"log"
"github.com/adampresley/swapi-go/swapi"
)
func main() {
client := swapi.NewClient()
person, status, err := client.GetPersonById(1)
if err != nil {
log.Fatalf("Cannot get person: %s", err.Error())
}
if status != 200 {
log.Println("HTTP error with message", result.ErrorMessage)
}
// Do something useful with this person
}