Starship Methods - adampresley/swapi-go GitHub Wiki

The Starship methods return information about the many types of starships 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.

Structures

type Starship struct {
	errors.Error

	MGLT                 string   `json:"MGLT"`
	CargoCapacity        string   `json:"cargo_capacity"`
	Consumables          string   `json:"consumables"`
	CostInCredits        string   `json:"cost_in_credits"`
	Created              string   `json:"created"`
	Crew                 string   `json:"crew"`
	Edited               string   `json:"edited"`
	HyperdriveRating     string   `json:"hyperdrive_rating"`
	Length               string   `json:"length"`
	Manufacturer         string   `json:"manufacturer"`
	MaxAtmospheringSpeed string   `json:"max_atmostphering_speed"`
	Model                string   `json:"model"`
	Name                 string   `json:"name"`
	Passengers           string   `json:"passengers"`
	Films                []string `json:"films"`
	Pilots               []string `json:"pilots"`
	StarshipClass        string   `json:"starship_class"`
	Url                  string   `json:"url"`
}

type StarshipCollection struct {
	errors.Error

	collection.SWAPIResultCollection
	Results []Starship `json:"results"`
}

Methods

GetAllStarships

Description: Returns a collection of Starship structures in the form of a StarshipCollection structure.

Returns: StarshipCollection structure, HTTP status code, error

Example:

package main

import (
	"log"

	"github.com/adampresley/swapi-go/swapi"
)

func main() {
	client := swapi.NewClient()
	starships, status, err := client.GetAllStarships()

	if err != nil {
		log.Fatalf("Cannot get starships: %s", err.Error())
	}

	if status != 200 {
		log.Println("HTTP error with message", result.ErrorMessage)
	}

	/*
	 * Iterate over the results and do something useful
	 */
	for _, starship := range starships.Results {
		// useful
	}
}

GetStarshipById

Description: Returns a single Starship structure by ID.

Returns: Starship structure, HTTP status code, error

Example:

package main

import (
	"log"

	"github.com/adampresley/swapi-go/swapi"
)

func main() {
	client := swapi.NewClient()
	starship, status, err := client.GetStarshipById(1)

	if err != nil {
		log.Fatalf("Cannot get starship: %s", err.Error())
	}

	if status != 200 {
		log.Println("HTTP error with message", result.ErrorMessage)
	}

	// Do something useful with this starship
}
⚠️ **GitHub.com Fallback** ⚠️