Documentation ¶
Overview ¶
Package pokeapi provides a Client and strong set of types for use with the PokéAPI project (https://pokeapi.co/docs/v2).
The Client also supports custom caching strategies - or cache.None if you intend on implementing your own. Under PokéAPI's Fair Use Policy (https://pokeapi.co/docs/v2#fairuse), you should "locally cache resources whenever you request them". This package aims to make meeting that criteria easy for you!
Resource doc comments in this module are generally taken directly from PokéAPI's own docs - with some edits to allow go doc to link between identifiers where possible.
A Massive Thank You to Paul Hallett & the PokéAPI contributor team for maintaining the api this package wraps :D.
Index ¶
- Constants
- Variables
- func NewHTTPError(resp *http.Response) error
- type APIResource
- type Ability
- type AbilityEffectChange
- type AbilityFlavorText
- type AbilityPokemon
- type AwesomeName
- type Berry
- type BerryFirmness
- type BerryFlavor
- type BerryFlavorMap
- type Cache
- type CacheLoader
- type ChainLink
- type Characteristic
- type Client
- func (c *Client) GetAbility(ctx context.Context, ident string) (*Ability, error)
- func (c *Client) GetBerry(ctx context.Context, ident string) (*Berry, error)
- func (c *Client) GetBerryFirmness(ctx context.Context, ident string) (*BerryFirmness, error)
- func (c *Client) GetBerryFlavor(ctx context.Context, ident string) (*BerryFlavor, error)
- func (c *Client) GetCharacteristic(ctx context.Context, id string) (*Characteristic, error)
- func (c *Client) GetContestEffect(ctx context.Context, id string) (*ContestEffect, error)
- func (c *Client) GetContestType(ctx context.Context, ident string) (*ContestType, error)
- func (c *Client) GetEggGroup(ctx context.Context, ident string) (*EggGroup, error)
- func (c *Client) GetEncounterCondition(ctx context.Context, ident string) (*EncounterCondition, error)
- func (c *Client) GetEncounterConditionValue(ctx context.Context, ident string) (*EncounterConditionValue, error)
- func (c *Client) GetEncounterMethod(ctx context.Context, ident string) (*EncounterMethod, error)
- func (c *Client) GetEvolutionChain(ctx context.Context, id string) (*EvolutionChain, error)
- func (c *Client) GetEvolutionTrigger(ctx context.Context, ident string) (*EvolutionTrigger, error)
- func (c *Client) GetGender(ctx context.Context, ident string) (*Gender, error)
- func (c *Client) GetGeneration(ctx context.Context, ident string) (*Generation, error)
- func (c *Client) GetGrowthRate(ctx context.Context, ident string) (*GrowthRate, error)
- func (c *Client) GetItem(ctx context.Context, ident string) (*Item, error)
- func (c *Client) GetItemAttribute(ctx context.Context, ident string) (*ItemAttribute, error)
- func (c *Client) GetItemCategory(ctx context.Context, ident string) (*ItemCategory, error)
- func (c *Client) GetItemFlingEffect(ctx context.Context, ident string) (*ItemFlingEffect, error)
- func (c *Client) GetItemPocket(ctx context.Context, ident string) (*ItemPocket, error)
- func (c *Client) GetLanguage(ctx context.Context, ident string) (*Language, error)
- func (c *Client) GetLocation(ctx context.Context, ident string) (*Location, error)
- func (c *Client) GetLocationArea(ctx context.Context, ident string) (*LocationArea, error)
- func (c *Client) GetMachine(ctx context.Context, id string) (*Machine, error)
- func (c *Client) GetMove(ctx context.Context, ident string) (*Move, error)
- func (c *Client) GetMoveAilment(ctx context.Context, ident string) (*MoveAilment, error)
- func (c *Client) GetMoveBattleStyle(ctx context.Context, ident string) (*MoveBattleStyle, error)
- func (c *Client) GetMoveCategory(ctx context.Context, ident string) (*MoveCategory, error)
- func (c *Client) GetMoveDamageClass(ctx context.Context, ident string) (*MoveDamageClass, error)
- func (c *Client) GetMoveLearnMethod(ctx context.Context, ident string) (*MoveLearnMethod, error)
- func (c *Client) GetMoveTarget(ctx context.Context, ident string) (*MoveTarget, error)
- func (c *Client) GetNature(ctx context.Context, ident string) (*Nature, error)
- func (c *Client) GetPalParkArea(ctx context.Context, ident string) (*PalParkArea, error)
- func (c *Client) GetPokeathlonStat(ctx context.Context, ident string) (*PokeathlonStat, error)
- func (c *Client) GetPokedex(ctx context.Context, ident string) (*Pokedex, error)
- func (c *Client) GetPokemon(ctx context.Context, ident string) (*Pokemon, error)
- func (c *Client) GetPokemonColor(ctx context.Context, ident string) (*PokemonColor, error)
- func (c *Client) GetPokemonEncounters(ctx context.Context, pokeIdent string) ([]PokemonLocationArea, error)
- func (c *Client) GetPokemonForm(ctx context.Context, ident string) (*PokemonForm, error)
- func (c *Client) GetPokemonHabitat(ctx context.Context, ident string) (*PokemonHabitat, error)
- func (c *Client) GetPokemonShape(ctx context.Context, ident string) (*PokemonShape, error)
- func (c *Client) GetPokemonSpecies(ctx context.Context, ident string) (*PokemonSpecies, error)
- func (c *Client) GetRegion(ctx context.Context, ident string) (*Region, error)
- func (c *Client) GetStat(ctx context.Context, ident string) (*Stat, error)
- func (c *Client) GetSuperContestEffect(ctx context.Context, id string) (*SuperContestEffect, error)
- func (c *Client) GetType(ctx context.Context, ident string) (*Type, error)
- func (c *Client) GetVersion(ctx context.Context, ident string) (*Version, error)
- func (c *Client) GetVersionGroup(ctx context.Context, ident string) (*VersionGroup, error)
- func (c *Client) ListAbilities(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Ability], Ability], error)
- func (c *Client) ListBerries(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Berry], Berry], error)
- func (c *Client) ListBerryFirmnesses(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[BerryFirmness], BerryFirmness], error)
- func (c *Client) ListBerryFlavors(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[BerryFlavor], BerryFlavor], error)
- func (c *Client) ListCharacteristics(ctx context.Context, opts *ListOpts) (*Page[APIResource[Characteristic], Characteristic], error)
- func (c *Client) ListContestEffects(ctx context.Context, opts *ListOpts) (*Page[APIResource[ContestEffect], ContestEffect], error)
- func (c *Client) ListContestTypes(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ContestType], ContestType], error)
- func (c *Client) ListEggGroups(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[EggGroup], EggGroup], error)
- func (c *Client) ListEncounterConditionValues(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[EncounterConditionValue], EncounterConditionValue], ...)
- func (c *Client) ListEncounterConditions(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[EncounterCondition], EncounterCondition], error)
- func (c *Client) ListEncounterMethods(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[EncounterMethod], EncounterMethod], error)
- func (c *Client) ListEvolutionChains(ctx context.Context, opts *ListOpts) (*Page[APIResource[EvolutionChain], EvolutionChain], error)
- func (c *Client) ListEvolutionTriggers(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[EvolutionTrigger], EvolutionTrigger], error)
- func (c *Client) ListGenders(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Gender], Gender], error)
- func (c *Client) ListGenerations(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Generation], Generation], error)
- func (c *Client) ListGrowthRates(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[GrowthRate], GrowthRate], error)
- func (c *Client) ListItemAttributes(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ItemAttribute], ItemAttribute], error)
- func (c *Client) ListItemCategories(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ItemCategory], ItemCategory], error)
- func (c *Client) ListItemFlingEffects(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ItemFlingEffect], ItemFlingEffect], error)
- func (c *Client) ListItemPockets(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ItemPocket], ItemPocket], error)
- func (c *Client) ListItems(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Item], Item], error)
- func (c *Client) ListLanguages(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Language], Language], error)
- func (c *Client) ListLocationAreas(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[LocationArea], LocationArea], error)
- func (c *Client) ListLocations(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Location], Location], error)
- func (c *Client) ListMachines(ctx context.Context, opts *ListOpts) (*Page[APIResource[Machine], Machine], error)
- func (c *Client) ListMoveAilments(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveAilment], MoveAilment], error)
- func (c *Client) ListMoveBattleStyles(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveBattleStyle], MoveBattleStyle], error)
- func (c *Client) ListMoveCategories(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveCategory], MoveCategory], error)
- func (c *Client) ListMoveDamageClasses(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveDamageClass], MoveDamageClass], error)
- func (c *Client) ListMoveLearnMethods(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveLearnMethod], MoveLearnMethod], error)
- func (c *Client) ListMoveTargets(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveTarget], MoveTarget], error)
- func (c *Client) ListMoves(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Move], Move], error)
- func (c *Client) ListNatures(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Nature], Nature], error)
- func (c *Client) ListPalParkAreas(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PalParkArea], PalParkArea], error)
- func (c *Client) ListPokeathlonStats(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokeathlonStat], PokeathlonStat], error)
- func (c *Client) ListPokedexes(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Pokedex], Pokedex], error)
- func (c *Client) ListPokemon(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Pokemon], Pokemon], error)
- func (c *Client) ListPokemonColors(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonColor], PokemonColor], error)
- func (c *Client) ListPokemonForms(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonForm], PokemonForm], error)
- func (c *Client) ListPokemonHabitats(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonHabitat], PokemonHabitat], error)
- func (c *Client) ListPokemonShapes(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonShape], PokemonShape], error)
- func (c *Client) ListPokemonSpecies(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonSpecies], PokemonSpecies], error)
- func (c *Client) ListRegions(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Region], Region], error)
- func (c *Client) ListStats(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Stat], Stat], error)
- func (c *Client) ListSuperContestEffects(ctx context.Context, opts *ListOpts) (*Page[APIResource[SuperContestEffect], SuperContestEffect], error)
- func (c *Client) ListTypes(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Type], Type], error)
- func (c *Client) ListVersionGroups(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[VersionGroup], VersionGroup], error)
- func (c *Client) ListVersions(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Version], Version], error)
- type ClientOpts
- type ContestComboDetail
- type ContestComboSets
- type ContestEffect
- type ContestName
- type ContestType
- type Description
- type Effect
- type EggGroup
- type Encounter
- type EncounterCondition
- type EncounterConditionValue
- type EncounterMethod
- type EncounterMethodRate
- type EncounterVersionDetails
- type EvolutionChain
- type EvolutionDetail
- type EvolutionTrigger
- type FlavorBerryMap
- type FlavorText
- type Gender
- type Generation
- type GenerationGameIndex
- type Genus
- type GettableAPIResource
- type GrowthRate
- type GrowthRateExperienceLevel
- type HTTPError
- type Identifier
- type Item
- type ItemAttribute
- type ItemCategory
- type ItemFlingEffect
- type ItemHolderPokemon
- type ItemHolderPokemonVersionDetail
- type ItemPocket
- type Language
- type ListOpts
- type Location
- type LocationArea
- type Machine
- type MachineVersionDetail
- type Move
- type MoveAilment
- type MoveBattleStyle
- type MoveBattleStylePreference
- type MoveCategory
- type MoveDamageClass
- type MoveFlavorText
- type MoveLearnMethod
- type MoveMetaData
- type MoveStatAffect
- type MoveStatAffectSets
- type MoveStatChange
- type MoveTarget
- type Name
- type NamedAPIResource
- type NamedIdentifier
- type Nature
- type NaturePokeathlonStatAffect
- type NaturePokeathlonStatAffectSets
- type NatureStatAffectSets
- type NatureStatChange
- type Page
- type PalParkArea
- type PalParkEncounterArea
- type PalParkEncounterSpecies
- type PastMoveStatValues
- type PokeathlonStat
- type Pokedex
- type Pokemon
- type PokemonAbility
- type PokemonColor
- type PokemonCries
- type PokemonEncounter
- type PokemonEntry
- type PokemonForm
- type PokemonFormType
- type PokemonHabitat
- type PokemonHeldItem
- type PokemonHeldItemVersion
- type PokemonLocationArea
- type PokemonMove
- type PokemonMoveVersion
- type PokemonShape
- type PokemonSpecies
- type PokemonSpeciesDexEntry
- type PokemonSpeciesGender
- type PokemonSpeciesVariety
- type PokemonStat
- type PokemonType
- type PokemonTypePast
- type Region
- type ResourceName
- type Stat
- type SuperContestEffect
- type Type
- type TypePokemon
- type TypeRelations
- type TypeRelationsPast
- type VerboseEffect
- type Version
- type VersionEncounterDetail
- type VersionGameIndex
- type VersionGroup
- type VersionGroupFlavorText
Examples ¶
Constants ¶
const DefaultPokeAPIRoot = `https://pokeapi.co/api/v2`
The DefaultPokeAPIRoot is the standard URL for PokéAPI. An alternative URL can be provided via [ClientOpts.PokeAPIRoot] for use with alternative builds of the API.
const PokemonLocationAreaEndpoint string = "encounters"
PokemonLocationAreaEndpoint is attached to a pokemon's url to get the set of locations it can be encountered in. It is the only sub-resource in the API, and as such does not have the ResourceName type as it cannot be listed directly. Use Client.GetPokemonEncounters or Pokemon.GetEncounters.
Variables ¶
var ( // ErrListExhausted is returned by Page.GetNext and Page.GetPrevious when // there are no more results in that direction. ErrListExhausted = fmt.Errorf("no more pages to fetch") // ErrNotFound is the error returned when attempting to retrieve a resource // that does not exist. ErrNotFound = HTTPError{Code: 404} )
Functions ¶
func NewHTTPError ¶ added in v0.2.0
Types ¶
type APIResource ¶
An APIResource represents the indirect link to another resource. Use the Get method to retrieve the full resource being referred to.
type Ability ¶
type Ability struct { NamedIdentifier IsMainSeries bool `json:"is_main_series"` // Whether this Ability originated in the main series of the video games. Generation NamedAPIResource[Generation] `json:"generation"` Names []Name `json:"names"` EffectEntries []VerboseEffect `json:"effect_entries"` EffectChanges []AbilityEffectChange `json:"effect_changes"` // The list of previous effects this ability has had across version groups. FlavorTextEntries []AbilityFlavorText `json:"flavor_text_entries"` Pokemon []AbilityPokemon `json:"pokemon"` }
type AbilityEffectChange ¶
type AbilityEffectChange struct { EffectEntries []Effect `json:"effect_entries"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` }
type AbilityFlavorText ¶
type AbilityFlavorText struct { FlavorText string `json:"flavor_text"` Language NamedAPIResource[Language] `json:"language"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` }
type AbilityPokemon ¶
type AbilityPokemon struct { IsHidden bool `json:"is_hidden"` Slot int `json:"slot"` // Pokémon have 3 ability 'slots' which hold references to possible abilities they could have. This is the slot of this ability for the referenced Pokémon. Pokemon NamedAPIResource[Pokemon] `json:"pokemon"` }
type AwesomeName ¶
type AwesomeName struct { AwesomeName string `json:"awesome_name"` Language NamedAPIResource[Language] `json:"language"` }
type Berry ¶
type Berry struct { NamedIdentifier Item NamedAPIResource[Item] `json:"item"` Flavors []BerryFlavorMap `json:"flavors"` GrowthTime int `json:"growth_time"` // In hours. Size int `json:"size"` // In millimeters. MaxHarvest int `json:"max_harvest"` SoilDryness int `json:"soil_dryness"` NaturalGiftPower int `json:"natural_gift_power"` NaturalGiftType NamedAPIResource[Type] `json:"natural_gift_type"` Smoothness int `json:"smoothness"` Firmness NamedAPIResource[BerryFirmness] `json:"firmness"` }
A Berry !
func (Berry) GrowthTimeDuration ¶
GrowthTimeDuration converts the Berry.GrowthTime (how long, in hours, it takes for a berry tree to grow 1 stage) to its corresponding time.Duration.
type BerryFirmness ¶
type BerryFirmness struct { NamedIdentifier Berries []NamedAPIResource[Berry] `json:"berries"` Names []Name `json:"names"` }
type BerryFlavor ¶
type BerryFlavor struct { NamedIdentifier Berries []FlavorBerryMap `json:"berries"` ContestType NamedAPIResource[ContestType] `json:"contest_type"` Names []Name `json:"names"` }
type BerryFlavorMap ¶
type BerryFlavorMap struct { Potency int `json:"potency"` Flavor NamedAPIResource[BerryFlavor] `json:"flavor"` }
type Cache ¶
type Cache interface {
Lookup(ctx context.Context, url string, loadOnMiss CacheLoader) (any, error)
}
A Cache allows the Client to Lookup a URL and retrieve the corresponding resource if it has been fetched before. `loadOnMiss` should only be called if the cache does not contain a value for the requested `url`. It is recommended (but not required) that concurrent lookups for the same `url` only make one call to a `loadOnMiss` between them.
type CacheLoader ¶ added in v0.2.0
A CacheLoader is called on cache misses to retrieve the value of the resource from an external source.
type ChainLink ¶
type ChainLink struct { IsBaby bool `json:"is_baby"` Species NamedAPIResource[PokemonSpecies] `json:"species"` EvolutionDetails []EvolutionDetail `json:"evolution_details"` EvolvesTo []ChainLink `json:"evolves_to"` }
type Characteristic ¶
type Characteristic struct { Identifier GeneModulo int `json:"gene_modulo"` // The remainder of the highest stat/IV divided by 5. PossibleValues []int `json:"possible_values"` // The possible values of the highest stat that would result in a Pokémon receiving this Characteristic when divided by 5. HighestStat NamedAPIResource[Stat] `json:"highest_stat"` // The stat which results in this Characteristic. Descriptions []Description `json:"descriptions"` }
A Characteristic indicates which stat contains a Pokémon's highest IV. A Pokémon's Characteristic is determined by the remainder of its highest IV divided by 5 (gene_modulo). Check out Bulbapedia for greater detail.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
The Client wraps a http.Client and a Cache to perform requests to PokéAPI.
All methods of the form `Get*` accept the id or name of the resource (unless otherwise stated) & return one instance of that resource.
All methods of the form `List*` will return the first Page of results, and accept an optional ListOpts parameter to permit you to start iteration wherever you like. This parameter may always be nil to start iteration from the beginning.
Return types are exact as possible. Pointer types are used to represent "optional" fields. Slice fields are always potentially empty.
Example ¶
package main import ( "context" "fmt" "os" "os/signal" "github.com/nightmarlin/pokeapi" "github.com/nightmarlin/pokeapi/cache" ) func main() { var ( ctx, cancel = signal.NotifyContext(context.Background(), os.Interrupt, os.Kill) printf = func(f string, a ...any) { _, _ = fmt.Fprintf(os.Stderr, f, a...) } ) defer cancel() c := pokeapi.NewClient(&pokeapi.ClientOpts{Cache: cache.NewLRU(nil)}) berries, err := c.ListBerries(ctx, nil) if err != nil { printf("failed to list all the berries: %v", err) return } printf("there are %d known berries", berries.Count) firstBerry, err := berries.Results[0].Get(ctx, c) if err != nil { printf("failed to fetch the first berry: %v", err) return } printf("the first berry is the %s berry", firstBerry.Name) reFetchedBerry, err := c.GetBerry(ctx, firstBerry.Ident()) // should hit the cache if err != nil { printf("failed to re-fetch the first berry: %v", err) return } printf("no really, it's the %s berry", reFetchedBerry.Name) reReFetchedBerry, err := c.GetBerry(ctx, firstBerry.Ident()) // definitely hits the cache! if err != nil { printf("failed to re-fetch the first berry: %v", err) return } printf("i am 100%% certain it's the %s berry", reReFetchedBerry.Name) item, err := firstBerry.Item.Get(ctx, c) if err != nil { printf("failed to fetch the item corresponding to the first berry: %v", err) return } printf("it typically costs %d$poké", item.Cost) category, err := item.Category.Get(ctx, c) if err != nil { printf("failed to fetch the item category for the first berry: %v", err) return } printf("and it goes in the %s pocket", category.Pocket.Name) }
Output:
func NewClient ¶
func NewClient(opts *ClientOpts) *Client
NewClient creates and returns a new Client with the provided ClientOpts applied. It is safe to use as NewClient(nil), but you are expected to do your own caching.
func (*Client) GetAbility ¶
func (*Client) GetBerryFirmness ¶
func (*Client) GetBerryFlavor ¶
func (*Client) GetCharacteristic ¶
GetCharacteristic only accepts the ID of the desired Characteristic.
func (*Client) GetContestEffect ¶
GetContestEffect only accepts the ID of the desired ContestEffect.
func (*Client) GetContestType ¶
func (*Client) GetEggGroup ¶
func (*Client) GetEncounterCondition ¶
func (*Client) GetEncounterConditionValue ¶
func (*Client) GetEncounterMethod ¶
func (*Client) GetEvolutionChain ¶
GetEvolutionChain only accepts the ID of the desired EvolutionChain.
func (*Client) GetEvolutionTrigger ¶
func (*Client) GetGeneration ¶
func (*Client) GetGrowthRate ¶
func (*Client) GetItemAttribute ¶
func (*Client) GetItemCategory ¶
func (*Client) GetItemFlingEffect ¶
func (*Client) GetItemPocket ¶
func (*Client) GetLanguage ¶
func (*Client) GetLocation ¶
func (*Client) GetLocationArea ¶
func (*Client) GetMachine ¶
GetMachine only accepts the ID of the desired Machine.
func (*Client) GetMoveAilment ¶
func (*Client) GetMoveBattleStyle ¶
func (*Client) GetMoveCategory ¶
func (*Client) GetMoveDamageClass ¶
func (*Client) GetMoveLearnMethod ¶
func (*Client) GetMoveTarget ¶
func (*Client) GetPalParkArea ¶
func (*Client) GetPokeathlonStat ¶
func (*Client) GetPokedex ¶
func (*Client) GetPokemon ¶
func (*Client) GetPokemonColor ¶
func (*Client) GetPokemonEncounters ¶
func (*Client) GetPokemonForm ¶
func (*Client) GetPokemonHabitat ¶
func (*Client) GetPokemonShape ¶
func (*Client) GetPokemonSpecies ¶
func (*Client) GetSuperContestEffect ¶
GetSuperContestEffect only accepts the ID of the desired SuperContestEffect.
func (*Client) GetVersion ¶
func (*Client) GetVersionGroup ¶
func (*Client) ListAbilities ¶
func (*Client) ListBerries ¶
func (*Client) ListBerryFirmnesses ¶
func (c *Client) ListBerryFirmnesses(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[BerryFirmness], BerryFirmness], error)
func (*Client) ListBerryFlavors ¶
func (c *Client) ListBerryFlavors(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[BerryFlavor], BerryFlavor], error)
func (*Client) ListCharacteristics ¶
func (c *Client) ListCharacteristics(ctx context.Context, opts *ListOpts) (*Page[APIResource[Characteristic], Characteristic], error)
func (*Client) ListContestEffects ¶
func (c *Client) ListContestEffects(ctx context.Context, opts *ListOpts) (*Page[APIResource[ContestEffect], ContestEffect], error)
func (*Client) ListContestTypes ¶
func (c *Client) ListContestTypes(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ContestType], ContestType], error)
func (*Client) ListEggGroups ¶
func (*Client) ListEncounterConditionValues ¶
func (c *Client) ListEncounterConditionValues(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[EncounterConditionValue], EncounterConditionValue], error)
func (*Client) ListEncounterConditions ¶
func (c *Client) ListEncounterConditions(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[EncounterCondition], EncounterCondition], error)
func (*Client) ListEncounterMethods ¶
func (c *Client) ListEncounterMethods(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[EncounterMethod], EncounterMethod], error)
func (*Client) ListEvolutionChains ¶
func (c *Client) ListEvolutionChains(ctx context.Context, opts *ListOpts) (*Page[APIResource[EvolutionChain], EvolutionChain], error)
func (*Client) ListEvolutionTriggers ¶
func (c *Client) ListEvolutionTriggers(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[EvolutionTrigger], EvolutionTrigger], error)
func (*Client) ListGenders ¶
func (*Client) ListGenerations ¶
func (c *Client) ListGenerations(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[Generation], Generation], error)
func (*Client) ListGrowthRates ¶
func (c *Client) ListGrowthRates(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[GrowthRate], GrowthRate], error)
func (*Client) ListItemAttributes ¶
func (c *Client) ListItemAttributes(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ItemAttribute], ItemAttribute], error)
func (*Client) ListItemCategories ¶
func (c *Client) ListItemCategories(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ItemCategory], ItemCategory], error)
func (*Client) ListItemFlingEffects ¶
func (c *Client) ListItemFlingEffects(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ItemFlingEffect], ItemFlingEffect], error)
func (*Client) ListItemPockets ¶
func (c *Client) ListItemPockets(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[ItemPocket], ItemPocket], error)
func (*Client) ListLanguages ¶
func (*Client) ListLocationAreas ¶
func (c *Client) ListLocationAreas(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[LocationArea], LocationArea], error)
func (*Client) ListLocations ¶
func (*Client) ListMachines ¶
func (*Client) ListMoveAilments ¶
func (c *Client) ListMoveAilments(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveAilment], MoveAilment], error)
func (*Client) ListMoveBattleStyles ¶
func (c *Client) ListMoveBattleStyles(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveBattleStyle], MoveBattleStyle], error)
func (*Client) ListMoveCategories ¶
func (c *Client) ListMoveCategories(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveCategory], MoveCategory], error)
func (*Client) ListMoveDamageClasses ¶
func (c *Client) ListMoveDamageClasses(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveDamageClass], MoveDamageClass], error)
func (*Client) ListMoveLearnMethods ¶
func (c *Client) ListMoveLearnMethods(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveLearnMethod], MoveLearnMethod], error)
func (*Client) ListMoveTargets ¶
func (c *Client) ListMoveTargets(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[MoveTarget], MoveTarget], error)
func (*Client) ListNatures ¶
func (*Client) ListPalParkAreas ¶
func (c *Client) ListPalParkAreas(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PalParkArea], PalParkArea], error)
func (*Client) ListPokeathlonStats ¶
func (c *Client) ListPokeathlonStats(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokeathlonStat], PokeathlonStat], error)
func (*Client) ListPokedexes ¶ added in v1.0.1
func (*Client) ListPokemon ¶ added in v1.0.1
func (*Client) ListPokemonColors ¶
func (c *Client) ListPokemonColors(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonColor], PokemonColor], error)
func (*Client) ListPokemonForms ¶
func (c *Client) ListPokemonForms(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonForm], PokemonForm], error)
func (*Client) ListPokemonHabitats ¶
func (c *Client) ListPokemonHabitats(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonHabitat], PokemonHabitat], error)
func (*Client) ListPokemonShapes ¶
func (c *Client) ListPokemonShapes(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonShape], PokemonShape], error)
func (*Client) ListPokemonSpecies ¶ added in v1.0.1
func (c *Client) ListPokemonSpecies(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[PokemonSpecies], PokemonSpecies], error)
func (*Client) ListRegions ¶
func (*Client) ListSuperContestEffects ¶
func (c *Client) ListSuperContestEffects(ctx context.Context, opts *ListOpts) (*Page[APIResource[SuperContestEffect], SuperContestEffect], error)
func (*Client) ListVersionGroups ¶
func (c *Client) ListVersionGroups(ctx context.Context, opts *ListOpts) (*Page[NamedAPIResource[VersionGroup], VersionGroup], error)
type ClientOpts ¶ added in v0.2.0
type ContestComboDetail ¶
type ContestComboDetail struct { UseBefore []NamedAPIResource[Move] `json:"use_before"` UseAfter []NamedAPIResource[Move] `json:"use_after"` }
type ContestComboSets ¶
type ContestComboSets struct { Normal *ContestComboDetail `json:"normal"` Super *ContestComboDetail `json:"super"` }
type ContestEffect ¶
type ContestEffect struct { Identifier Appeal int `json:"appeal"` // The base number of hearts the user of this move gets. Jam int `json:"jam"` // The base number of hearts the user's opponent loses. EffectEntries []Effect `json:"effect_entries"` // The result of this contest effect listed in different languages. FlavorTextEntries []FlavorText `json:"flavor_text_entries"` }
type ContestName ¶
type ContestName struct { Name string `json:"name"` Color string `json:"color"` // The color associated with this contest's name. May be empty. Language NamedAPIResource[Language] `json:"language"` }
type ContestType ¶
type ContestType struct { NamedIdentifier BerryFlavour NamedAPIResource[BerryFlavor] `json:"berry_flavour"` // The BerryFlavor that correlates with this contest type. Names []ContestName `json:"names"` }
type Description ¶
type Description struct { Description string `json:"description"` Language NamedAPIResource[Language] `json:"language"` }
A Description is a contextual description of the resource in the Language referenced.
type Effect ¶
type Effect struct { Description string `json:"description"` Language NamedAPIResource[Language] `json:"language"` }
An Effect is a localized text effect of the resource in the Language referenced.
type EggGroup ¶
type EggGroup struct { NamedIdentifier Names []Name `json:"names"` PokemonSpecies []NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` }
type Encounter ¶
type Encounter struct { MinLevel int `json:"min_level"` MaxLevel int `json:"max_level"` ConditionValues []NamedAPIResource[EncounterConditionValue] `json:"condition_values"` // A list of EncounterConditionValue s that must be in effect for this encounter to occur. Chance int `json:"chance"` // % chance for this encounter to occur. Method NamedAPIResource[EncounterMethod] `json:"method"` }
type EncounterCondition ¶
type EncounterCondition struct { NamedIdentifier Names []Name `json:"names"` Values []NamedAPIResource[EncounterConditionValue] `json:"values"` }
type EncounterConditionValue ¶
type EncounterConditionValue struct { NamedIdentifier Condition NamedAPIResource[EncounterCondition] `json:"condition"` Names []Name `json:"names"` }
type EncounterMethod ¶
type EncounterMethod struct { NamedIdentifier Order int `json:"order"` // A good value for sorting. Names []Name `json:"names"` }
type EncounterMethodRate ¶
type EncounterMethodRate struct { EncounterMethod NamedAPIResource[EncounterMethod] `json:"encounter_method"` VersionDetails []EncounterVersionDetails `json:"version_details"` }
type EncounterVersionDetails ¶
type EncounterVersionDetails struct { Rate int `json:"rate"` Version NamedAPIResource[Version] `json:"version"` }
type EvolutionChain ¶
type EvolutionChain struct { Identifier BabyTriggerItem *NamedAPIResource[Item] `json:"baby_trigger_item"` // The Item that a Pokémon would be holding when mating that would trigger the egg hatching a baby Pokémon rather than a basic Pokémon. Chain *ChainLink `json:"chain"` }
type EvolutionDetail ¶
type EvolutionDetail struct { Item *NamedAPIResource[Item] `json:"item"` Trigger NamedAPIResource[EvolutionTrigger] `json:"trigger"` Gender *int `json:"gender"` // The id of the gender of the evolving Pokémon species must be in order to evolve into this Pokémon species. HeldItem *NamedAPIResource[Item] `json:"held_item"` KnownMove *NamedAPIResource[Move] `json:"known_move"` KnownMoveType *NamedAPIResource[Type] `json:"known_move_type"` Location *NamedAPIResource[Location] `json:"location"` MinLevel *int `json:"min_level"` MinHappiness *int `json:"min_happiness"` MinBeauty *int `json:"min_beauty"` MinAffection *int `json:"min_affection"` NeedsOverworldRain bool `json:"needs_overworld_rain"` PartySpecies *NamedAPIResource[PokemonSpecies] `json:"party_species"` // The Pokémon species that must be in the players party in order for the evolving Pokémon species to evolve into this Pokémon species. PartyType *NamedAPIResource[Type] `json:"party_type"` // The player must have a Pokémon of this type in their party during the evolution trigger event in order for the evolving Pokémon species to evolve into this Pokémon species RelativePhysicalStats *int `json:"relative_physical_stats"` // The required relation between the Pokémon's Attack and Defense stats. 1 means Attack > Defense. 0 means Attack = Defense. -1 means Attack < Defense. TimeOfDay string `json:"time_of_day"` TradeSpecies *NamedAPIResource[PokemonSpecies] `json:"trade_species"` TurnUpsideDown bool `json:"turn_upside_down"` }
type EvolutionTrigger ¶
type EvolutionTrigger struct { NamedIdentifier Names []Name `json:"names"` PokemonSpecies []NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` }
type FlavorBerryMap ¶
type FlavorBerryMap struct { Potency int `json:"potency"` Berry NamedAPIResource[Berry] `json:"berry"` }
type FlavorText ¶
type FlavorText struct { FlavorText string `json:"flavor_text"` // The localized flavor text for an API resource in the Language referenced. Language NamedAPIResource[Language] `json:"language"` Version NamedAPIResource[Version] `json:"version"` // The game version this flavor text is extracted from. }
func (FlavorText) NormalizedFlavorText ¶
func (ft FlavorText) NormalizedFlavorText() string
NormalizedFlavorText implements the recommendation at https://github.com/veekun/pokedex/issues/218 to correctly render FlavorText.FlavorText as the expected string.
type Gender ¶
type Gender struct { NamedIdentifier PokemonSpeciesDetails []PokemonSpeciesGender `json:"pokemon_species_details"` // A list of Pokémon species that can be this Gender and how likely it is that they will be. RequiredForEvolution []NamedAPIResource[PokemonSpecies] `json:"required_for_evolution"` }
type Generation ¶
type Generation struct { NamedIdentifier Abilities []NamedAPIResource[Ability] `json:"abilities"` Names []Name `json:"names"` MainRegion NamedAPIResource[Region] `json:"main_region"` Moves []NamedAPIResource[Move] `json:"moves"` PokemonSpecies []NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` Types []NamedAPIResource[Type] `json:"types"` VersionGroups []NamedAPIResource[VersionGroup] `json:"version_groups"` }
type GenerationGameIndex ¶
type GenerationGameIndex struct { GameIndex int `json:"game_index"` // An internal ID of a resource within game data. Generation NamedAPIResource[Generation] `json:"generation"` }
type Genus ¶
type Genus struct { Genus string `json:"genus"` Language NamedAPIResource[Language] `json:"language"` }
type GettableAPIResource ¶ added in v0.3.0
GettableAPIResource is implemented by APIResource and NamedAPIResource to allow resources to be directly retrieved by their reference, either as part of a Page or when referenced by another resource.
type GrowthRate ¶
type GrowthRate struct { NamedIdentifier Formula string `json:"formula"` // The LaTeX formula used to calculate the rate at which the Pokémon species gains level. Descriptions []Description `json:"descriptions"` Levels []GrowthRateExperienceLevel `json:"levels"` // A list of levels and the amount of experience needed to attain them based on this growth rate. PokemonSpecies []NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` }
type HTTPError ¶ added in v0.2.0
type HTTPError struct{ Code int }
HTTPError represents an error returned by a failed HTTP request. As a special case, 404 Not Found returns ErrNotFound instead.
type Identifier ¶
type Identifier struct {
ID int `json:"id"`
}
An Identifier is embedded into all retrievable resources. It makes it easy to convert the numbered ID field to a string for use in api calls.
A resource directly embedding an Identifier will have an unnamed get/list client function pair generated for it by gettergen.
func (Identifier) Ident ¶
func (id Identifier) Ident() string
Ident returns the api id for this resource as a string for use in api calls.
type Item ¶
type Item struct { NamedIdentifier FlingPower *int `json:"fling_power"` FlingEffect *NamedAPIResource[ItemFlingEffect] `json:"fling_effect"` Cost int `json:"cost"` Attributes []NamedAPIResource[ItemAttribute] `json:"attributes"` Category NamedAPIResource[ItemCategory] `json:"category"` EffectEntries []VerboseEffect `json:"effect_entries"` FlavorTextEntries []VersionGroupFlavorText `json:"flavor_text_entries"` GameIndices []GenerationGameIndex `json:"game_indices"` Names []Name `json:"names"` Sprites sprites.Item `json:"sprites"` HeldByPokemon []ItemHolderPokemon `json:"held_by_pokemon"` BabyTriggerFor *APIResource[EvolutionChain] `json:"baby_trigger_for"` Machines []MachineVersionDetail `json:"machines"` }
type ItemAttribute ¶
type ItemAttribute struct { NamedIdentifier Names []Name `json:"names"` Descriptions []Description `json:"descriptions"` }
type ItemCategory ¶
type ItemCategory struct { NamedIdentifier Items []NamedAPIResource[Item] `json:"items"` Names []Name `json:"names"` Pocket NamedAPIResource[ItemPocket] `json:"pocket"` }
type ItemFlingEffect ¶
type ItemFlingEffect struct { NamedIdentifier EffectEntries []Effect `json:"effect_entries"` Items []NamedAPIResource[Item] `json:"items"` }
type ItemHolderPokemon ¶
type ItemHolderPokemon struct { Pokemon NamedAPIResource[Pokemon] `json:"pokemon"` VersionDetails []ItemHolderPokemonVersionDetail `json:"version_details"` }
type ItemHolderPokemonVersionDetail ¶
type ItemHolderPokemonVersionDetail struct { Rarity int `json:"rarity"` Version NamedAPIResource[Version] `json:"version"` }
type ItemPocket ¶
type ItemPocket struct { NamedIdentifier Categories []NamedAPIResource[ItemCategory] `json:"categories"` Names []Name `json:"names"` }
type Language ¶
type Language struct { NamedIdentifier Official bool `json:"official"` IS369 string `json:"is_369"` IS3166 string `json:"is_3166"` Names []Name `json:"names"` }
type ListOpts ¶ added in v1.0.0
type ListOpts struct {
Limit, Offset int
}
ListOpts are available on all List* endpoints, allowing you to set up your own pagination start point. Pagination will continue using the provided Limit for every page.
type Location ¶
type Location struct { NamedIdentifier Region *NamedAPIResource[Region] `json:"region"` Names []Name `json:"names"` GameIndices []GenerationGameIndex `json:"game_indices"` Areas []NamedAPIResource[LocationArea] `json:"areas"` }
type LocationArea ¶
type LocationArea struct { NamedIdentifier GameIndex int `json:"game_index"` // The internal id of an API resource within game data. EncounterMethodRates []EncounterMethodRate `json:"encounter_method_rates"` Location NamedAPIResource[Location] `json:"location"` Names []Name `json:"names"` PokemonEncounters []PokemonEncounter `json:"pokemon_encounters"` }
type Machine ¶
type Machine struct { Identifier Item NamedAPIResource[Item] `json:"item"` Move NamedAPIResource[Move] `json:"move"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` }
type MachineVersionDetail ¶
type MachineVersionDetail struct { Machine APIResource[Machine] `json:"machine"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` }
type Move ¶
type Move struct { NamedIdentifier Accuracy *int `json:"accuracy"` EffectChance *int `json:"effect_chance"` PP int `json:"pp"` Priority int `json:"priority"` // -8 <= Priority <= 8 Power *int `json:"power"` // May be 0 for moves with variable power. DamageClass NamedAPIResource[MoveDamageClass] `json:"damage_class"` Generation NamedAPIResource[Generation] `json:"generation"` LearnedByPokemon []NamedAPIResource[Pokemon] `json:"learned_by_pokemon"` Machines []MachineVersionDetail `json:"machines"` Meta *MoveMetaData `json:"meta"` PastValues []PastMoveStatValues `json:"past_values"` StatChanges []MoveStatChange `json:"stat_changes"` Target NamedAPIResource[MoveTarget] `json:"target"` Type NamedAPIResource[Type] `json:"type"` ContestCombos *ContestComboSets `json:"contest_combos"` ContestType *NamedAPIResource[ContestType] `json:"contest_type"` ContestEffect *APIResource[ContestEffect] `json:"contest_effect"` SuperContestEffect *APIResource[SuperContestEffect] `json:"super_contest_effect"` EffectEntries []VerboseEffect `json:"effect_entries"` EffectChanges []AbilityEffectChange `json:"effect_changes"` FlavorTextEntries []MoveFlavorText `json:"flavor_text_entries"` }
type MoveAilment ¶
type MoveAilment struct { NamedIdentifier Moves []NamedAPIResource[Move] `json:"moves"` Names []Name `json:"names"` }
type MoveBattleStyle ¶
type MoveBattleStyle struct { NamedIdentifier Names []Name `json:"names"` }
type MoveBattleStylePreference ¶
type MoveBattleStylePreference struct { LowHPPreference int `json:"low_hp_preference"` HighHPPreference int `json:"high_hp_preference"` MoveBattleStyle NamedAPIResource[MoveBattleStyle] `json:"move_battle_style"` }
type MoveCategory ¶
type MoveCategory struct { NamedIdentifier Moves []NamedAPIResource[Move] `json:"moves"` Descriptions []Description `json:"descriptions"` }
type MoveDamageClass ¶
type MoveDamageClass struct { NamedIdentifier Descriptions []Description `json:"descriptions"` Moves []NamedAPIResource[Move] `json:"moves"` Names []Name `json:"names"` }
type MoveFlavorText ¶
type MoveFlavorText struct { FlavorText string `json:"flavor_text"` Language NamedAPIResource[Language] `json:"language"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` }
type MoveLearnMethod ¶
type MoveLearnMethod struct { NamedIdentifier Descriptions []Description `json:"descriptions"` Names []Name `json:"names"` VersionGroups []NamedAPIResource[VersionGroup] `json:"version_groups"` }
type MoveMetaData ¶
type MoveMetaData struct { Ailment NamedAPIResource[MoveAilment] `json:"ailment"` Category NamedAPIResource[MoveCategory] `json:"category"` MinHits *int `json:"min_hits"` // The minimum number of times this move hits. Null if it always only hits once. MaxHits *int `json:"max_hits"` // The maximum number of times this move hits. Null if it always only hits once. MinTurns *int `json:"min_turns"` // The minimum number of turns this move continues to take effect. Null if it always only lasts one turn. MaxTurns *int `json:"max_turns"` // The maximum number of turns this move continues to take effect. Null if it always only lasts one turn. Drain int `json:"drain"` // HP drain (if positive) or Recoil damage (if negative), in percent of damage done. Healing int `json:"healing"` // The amount of hp gained by the attacking Pokémon, in percent of it's maximum HP. CritRate int `json:"crit_rate"` AilmentChance int `json:"ailment_chance"` FlinchChance int `json:"flinch_chance"` StatChance int `json:"stat_chance"` }
type MoveStatAffect ¶
type MoveStatAffect struct { Change int `json:"change"` Move NamedAPIResource[Move] `json:"move"` }
type MoveStatAffectSets ¶
type MoveStatAffectSets struct { Increase []MoveStatAffect `json:"increase"` Decrease []MoveStatAffect `json:"decrease"` }
type MoveStatChange ¶
type MoveStatChange struct { Change int `json:"change"` Stat NamedAPIResource[Stat] `json:"stat"` }
type MoveTarget ¶
type MoveTarget struct { NamedIdentifier Descriptions []Description `json:"descriptions"` Moves []NamedAPIResource[Move] `json:"moves"` Names []Name `json:"names"` }
type Name ¶
type Name struct { Name string `json:"name"` Language NamedAPIResource[Language] `json:"language"` }
A Name is a localized representation of the resource's name in the Language referenced.
type NamedAPIResource ¶
type NamedAPIResource[T any] struct { APIResource[T] Name string `json:"name"` }
A NamedAPIResource is similar to an APIResource, but it provides an additional human-readable Name. Use the APIResource.Get method to retrieve the full resource being referred to.
type NamedIdentifier ¶
type NamedIdentifier struct { Identifier Name string `json:"name"` }
A NamedIdentifier is embedded into resources that are named.
A resource directly embedding a NamedIdentifier will have a named get/list client function pair generated for it by gettergen.
type Nature ¶
type Nature struct { NamedIdentifier Names []Name `json:"names"` DecreasedStat *NamedAPIResource[Stat] `json:"decreased_stat"` IncreasedStat *NamedAPIResource[Stat] `json:"increased_stat"` HatesFlavour *NamedAPIResource[BerryFlavor] `json:"hates_flavour"` LikesFlavour *NamedAPIResource[BerryFlavor] `json:"likes_flavour"` PokeathlonStatChanges []NatureStatChange `json:"pokeathlon_stat_changes"` MoveBattleStylePreferences []MoveBattleStylePreference `json:"move_battle_style_preferences"` }
type NaturePokeathlonStatAffect ¶
type NaturePokeathlonStatAffect struct { MaxChange int `json:"max_change"` // The maximum amount of change to the referenced Pokéathlon stat. Nature NamedAPIResource[Nature] `json:"nature"` }
type NaturePokeathlonStatAffectSets ¶
type NaturePokeathlonStatAffectSets struct { Increase []NaturePokeathlonStatAffect `json:"increase"` Decrease []NaturePokeathlonStatAffect `json:"decrease"` }
type NatureStatAffectSets ¶
type NatureStatAffectSets struct { Increase []NamedAPIResource[Nature] `json:"increase"` Decrease []NamedAPIResource[Nature] `json:"decrease"` }
type NatureStatChange ¶
type NatureStatChange struct { MaxChange int `json:"max_change"` PokeathlonStat NamedAPIResource[PokeathlonStat] `json:"pokeathlon_stat"` }
type Page ¶
type Page[R GettableAPIResource[T], T any] struct { Count int `json:"count"` // The total number of resources available from this API. Next *string `json:"next"` // The URL for the next page in the list. Previous *string `json:"previous"` // The URL for the previous page in the list. Results []R `json:"results"` }
A Page represents a list of APIResource s or NamedAPIResource s. It also includes information on the total number of resources in the result set, and how to view the Next & Previous Page s.
If a page is requested that does not exist, ErrListExhausted is returned. PokéAPI does not distinguish between "resource not found" and "no items at page index", so this is a design decision taken to optimise the common case (as all Resources exported by this package are guaranteed to be able to be List-ed)
client.ListBerries(ctx, &pokeapi.ListOpts{Offset: 1000}) => ErrListExhausted
type PalParkArea ¶
type PalParkArea struct { NamedIdentifier Names []Name `json:"names"` PokemonEncounters []PalParkEncounterSpecies `json:"pokemon_encounters"` }
type PalParkEncounterArea ¶
type PalParkEncounterArea struct { BaseScore int `json:"base_score"` // The base score given to the player when the referenced Pokémon is caught during a pal park run. Rate int `json:"rate"` // The base rate for encountering the referenced Pokémon in this pal park area. Area NamedAPIResource[PalParkArea] `json:"area"` }
type PalParkEncounterSpecies ¶
type PalParkEncounterSpecies struct { BaseScore int `json:"base_score"` // The base score given to the player when this Pokémon is caught during a pal park run. Rate int `json:"rate"` // The base rate for encountering this Pokémon in this pal park area. PokemonSpecies NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` }
type PastMoveStatValues ¶
type PastMoveStatValues struct { Accuracy *int `json:"accuracy"` EffectChance *int `json:"effect_chance"` Power *int `json:"power"` PP *int `json:"pp"` EffectEntries []VerboseEffect `json:"effect_entries"` Type *NamedAPIResource[Type] `json:"type"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` }
type PokeathlonStat ¶
type PokeathlonStat struct { NamedIdentifier Names []Name `json:"names"` AffectingNatures []NaturePokeathlonStatAffectSets `json:"affecting_natures"` }
type Pokedex ¶
type Pokedex struct { NamedIdentifier IsMainSeries bool `json:"is_main_series"` Descriptions []Description `json:"descriptions"` Names []Name `json:"names"` PokemonEntries []PokemonEntry `json:"pokemon_entries"` Region *NamedAPIResource[Region] `json:"region"` VersionGroups []NamedAPIResource[VersionGroup] `json:"version_groups"` }
type Pokemon ¶
type Pokemon struct { NamedIdentifier BaseExperience int `json:"base_experience"` Height int `json:"height"` // The height of this Pokémon in decimeters. IsDefault bool `json:"is_default"` // Set for exactly one Pokémon used as the default for each species. Order int `json:"order"` // Order for sorting. Almost national order, except families are grouped together. Weight int `json:"weight"` // The weight of this Pokémon in hectograms. Abilities []PokemonAbility `json:"abilities"` Forms []NamedAPIResource[PokemonForm] `json:"forms"` GameIndices []VersionGameIndex `json:"game_indices"` HeldItems []PokemonHeldItem `json:"held_items"` // A list of items this Pokémon may be holding when encountered. Moves []PokemonMove `json:"moves"` PastTypes []PokemonTypePast `json:"past_types"` Sprites sprites.Pokemon `json:"sprites"` Cries PokemonCries `json:"cries"` Species NamedAPIResource[PokemonSpecies] `json:"species"` Stats []PokemonStat `json:"stats"` Types []PokemonType `json:"types"` // A URL to the PokemonLocationArea s this Pokemon can be encountered in. // To retrieve, use Client.GetPokemonEncounters or Pokemon.GetEncounters. LocationAreaEncounters string `json:"location_area_encounters"` }
func (Pokemon) GetEncounters ¶
func (Pokemon) HeightMillimeters ¶
HeightMillimeters converts Pokemon.Height (in decimeters) to the more common measurement millimeters.
func (Pokemon) WeightGrams ¶
WeightGrams converts Pokemon.Weight (in hectograms) to the more common measurement grams.
type PokemonAbility ¶
type PokemonAbility struct { IsHidden bool `json:"is_hidden"` Slot int `json:"slot"` // The slot this ability occupies in this Pokémon species. Ability NamedAPIResource[Ability] `json:"ability"` }
type PokemonColor ¶
type PokemonColor struct { NamedIdentifier Names []string `json:"names"` PokemonSpecies []NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` }
type PokemonCries ¶
PokemonCries are a set of URLs pointing to the sound files for the Pokemon's cry.
type PokemonEncounter ¶
type PokemonEncounter struct { Pokemon NamedAPIResource[Pokemon] `json:"pokemon"` VersionDetails []VersionEncounterDetail `json:"version_details"` }
type PokemonEntry ¶
type PokemonEntry struct { EntryNumber int `json:"entry_number"` PokemonSpecies NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` }
type PokemonForm ¶
type PokemonForm struct { NamedIdentifier Order int `json:"order"` // The order in which forms should be sorted within all forms. Multiple forms may have equal order, in which case they should fall back on sorting by name. FormOrder int `json:"form_order"` // The order in which forms should be sorted within a species' forms. IsDefault bool `json:"is_default"` // True for exactly one form used as the default for each Pokémon. IsBattleOnly bool `json:"is_battle_only"` IsMega bool `json:"is_mega"` FormName string `json:"form_name"` Types []PokemonFormType `json:"types"` Sprites sprites.PokemonForm `json:"sprites"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` // The version group this Pokémon form was introduced in. Names []Name `json:"names"` // The form specific full name of this Pokémon form, or empty if the form does not have a specific name. FormNames []Name `json:"form_names"` // The form specific full name of this Pokémon form, or empty if the form does not have a specific name. }
type PokemonFormType ¶
type PokemonFormType struct { Slot int `json:"slot"` Type NamedAPIResource[Type] `json:"type"` }
type PokemonHabitat ¶
type PokemonHabitat struct { NamedIdentifier Names []Name `json:"names"` PokemonSpecies []NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` }
type PokemonHeldItem ¶
type PokemonHeldItem struct { Item NamedAPIResource[Item] `json:"item"` VersionDetails []PokemonHeldItemVersion `json:"version_details"` }
type PokemonHeldItemVersion ¶
type PokemonHeldItemVersion struct { Version NamedAPIResource[Version] `json:"version"` Rarity int `json:"rarity"` }
type PokemonLocationArea ¶
type PokemonLocationArea struct { LocationArea NamedAPIResource[LocationArea] `json:"location_area"` VersionDetails []VersionEncounterDetail `json:"version_details"` }
type PokemonMove ¶
type PokemonMove struct { Move NamedAPIResource[Move] `json:"move"` VersionGroupDetails []PokemonMoveVersion `json:"version_group_details"` }
type PokemonMoveVersion ¶
type PokemonMoveVersion struct { MoveLearnMethod NamedAPIResource[MoveLearnMethod] `json:"move_learn_method"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` LevelLearnedAt int `json:"level_learned_at"` // The minimum level to learn the move. }
type PokemonShape ¶
type PokemonShape struct { NamedIdentifier AwesomeNames []AwesomeName `json:"awesome_names"` // The "scientific" name of this Pokémon shape listed in different languages. Names []Name `json:"names"` PokemonSpecies []NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` }
type PokemonSpecies ¶
type PokemonSpecies struct { NamedIdentifier Order int `json:"order"` // The order in which species should be sorted. Based on National Dex order, except families are grouped together and sorted by stage. GenderRate int `json:"gender_rate"` // The chance of this Pokémon being female, in eighths; or -1 for genderless. CaptureRate uint8 `json:"capture_rate"` // The base capture rate; up to 255. The higher the number, the easier the catch. BaseHappiness uint8 `json:"base_happiness"` // The happiness when caught by a normal Pokéball; up to 255. The higher the number, the happier the Pokémon. IsBaby bool `json:"is_baby"` IsLegendary bool `json:"is_legendary"` IsMythical bool `json:"is_mythical"` HatchCounter int `json:"hatch_counter"` HasGenderDifferences bool `json:"has_gender_differences"` FormsSwitchable bool `json:"forms_switchable"` GrowthRate NamedAPIResource[GrowthRate] `json:"growth_rate"` PokedexNumbers []PokemonSpeciesDexEntry `json:"pokedex_numbers"` EggGroups []NamedAPIResource[EggGroup] `json:"egg_groups"` Color NamedAPIResource[PokemonColor] `json:"color"` Shape NamedAPIResource[PokemonShape] `json:"shape"` EvolvesFromSpecies *NamedAPIResource[PokemonSpecies] `json:"evolves_from_species"` EvolutionChain APIResource[EvolutionChain] `json:"evolution_chain"` Habitat *NamedAPIResource[PokemonHabitat] `json:"habitat"` Generation NamedAPIResource[Generation] `json:"generation"` // The generation this Pokémon species was introduced in. Names []Name `json:"names"` PalParkEncounters []PalParkEncounterArea `json:"pal_park_encounters"` FlavorTextEntries []FlavorText `json:"flavor_text_entries"` FormDescriptions []Description `json:"form_descriptions"` Genera []Genus `json:"genera"` Varieties []PokemonSpeciesVariety `json:"varieties"` }
type PokemonSpeciesDexEntry ¶
type PokemonSpeciesDexEntry struct { EntryNumber int `json:"entry_number"` Pokedex []NamedAPIResource[Pokedex] `json:"pokedex"` }
type PokemonSpeciesGender ¶
type PokemonSpeciesGender struct { Rate int `json:"rate"` // The chance of this Pokémon being female, in eighths; or -1 for genderless. PokemonSpecies NamedAPIResource[PokemonSpecies] `json:"pokemon_species"` }
type PokemonSpeciesVariety ¶
type PokemonSpeciesVariety struct { IsDefault bool `json:"is_default"` Pokemon NamedAPIResource[Pokemon] `json:"pokemon"` }
type PokemonStat ¶
type PokemonStat struct { Stat NamedAPIResource[Stat] `json:"stat"` Effort int `json:"effort"` // The effort points (EV) the Pokémon has in the stat. BaseStat int `json:"base_stat"` }
type PokemonType ¶
type PokemonType struct { Slot int `json:"slot"` Type NamedAPIResource[Type] `json:"type"` }
type PokemonTypePast ¶
type PokemonTypePast struct { Generation NamedAPIResource[Generation] `json:"generation"` // The last generation in which the referenced pokémon had the listed types. Types []PokemonType `json:"types"` // The types the referenced pokémon had up to and including the listed generation. }
type Region ¶
type Region struct { NamedIdentifier Locations []NamedAPIResource[Location] `json:"locations"` Names []Name `json:"names"` MainGeneration *NamedAPIResource[Generation] `json:"main_generation"` // The generation this region was introduced in. Pokedexes []NamedAPIResource[Pokedex] `json:"pokedexes"` VersionGroups []NamedAPIResource[VersionGroup] `json:"version_groups"` }
type ResourceName ¶ added in v0.3.0
type ResourceName[R GettableAPIResource[T], T any] string
A ResourceName is the kebab-case name for a PokéAPI endpoint. Resources can always be called with
GET {root}/resource
to return a Page of APIResource(s) pointing to instances of the resource or
GET {root}/resource/{id or name}
to get a single instance of that resource. The helper methods List and Get correspond to these api calls.
const AbilityResource ResourceName[NamedAPIResource[Ability], Ability] = "ability"
const BerryFirmnessResource ResourceName[NamedAPIResource[BerryFirmness], BerryFirmness] = "berry-firmness"
const BerryFlavorResource ResourceName[NamedAPIResource[BerryFlavor], BerryFlavor] = "berry-flavor"
const BerryResource ResourceName[NamedAPIResource[Berry], Berry] = "berry"
const CharacteristicResource ResourceName[APIResource[Characteristic], Characteristic] = "characteristic"
const ContestEffectResource ResourceName[APIResource[ContestEffect], ContestEffect] = "contest-effect"
const ContestTypeResource ResourceName[NamedAPIResource[ContestType], ContestType] = "contest-type"
const EggGroupResource ResourceName[NamedAPIResource[EggGroup], EggGroup] = "egg-group"
const EncounterConditionResource ResourceName[NamedAPIResource[EncounterCondition], EncounterCondition] = "encounter-condition"
const EncounterConditionValueResource ResourceName[NamedAPIResource[EncounterConditionValue], EncounterConditionValue] = "encounter-condition-value"
const EncounterMethodResource ResourceName[NamedAPIResource[EncounterMethod], EncounterMethod] = "encounter-method"
const EvolutionChainResource ResourceName[APIResource[EvolutionChain], EvolutionChain] = "evolution-chain"
const EvolutionTriggerResource ResourceName[NamedAPIResource[EvolutionTrigger], EvolutionTrigger] = "evolution-trigger"
const GenderResource ResourceName[NamedAPIResource[Gender], Gender] = "gender"
const GenerationResource ResourceName[NamedAPIResource[Generation], Generation] = "generation"
const GrowthRateResource ResourceName[NamedAPIResource[GrowthRate], GrowthRate] = "growth-rate"
const ItemAttributeResource ResourceName[NamedAPIResource[ItemAttribute], ItemAttribute] = "item-attribute"
const ItemCategoryResource ResourceName[NamedAPIResource[ItemCategory], ItemCategory] = "item-category"
const ItemFlingEffectResource ResourceName[NamedAPIResource[ItemFlingEffect], ItemFlingEffect] = "item-fling-effect"
const ItemPocketResource ResourceName[NamedAPIResource[ItemPocket], ItemPocket] = "item-pocket"
const ItemResource ResourceName[NamedAPIResource[Item], Item] = "item"
const LanguageResource ResourceName[NamedAPIResource[Language], Language] = "language"
const LocationAreaResource ResourceName[NamedAPIResource[LocationArea], LocationArea] = "location-area"
const LocationResource ResourceName[NamedAPIResource[Location], Location] = "location"
const MachineResource ResourceName[APIResource[Machine], Machine] = "machine"
const MoveAilmentResource ResourceName[NamedAPIResource[MoveAilment], MoveAilment] = "move-ailment"
const MoveBattleStyleResource ResourceName[NamedAPIResource[MoveBattleStyle], MoveBattleStyle] = "move-battle-style"
const MoveCategoryResource ResourceName[NamedAPIResource[MoveCategory], MoveCategory] = "move-category"
const MoveDamageClassResource ResourceName[NamedAPIResource[MoveDamageClass], MoveDamageClass] = "move-damage-class"
const MoveLearnMethodResource ResourceName[NamedAPIResource[MoveLearnMethod], MoveLearnMethod] = "move-learn-method"
const MoveResource ResourceName[NamedAPIResource[Move], Move] = "move"
const MoveTargetResource ResourceName[NamedAPIResource[MoveTarget], MoveTarget] = "move-target"
const NatureResource ResourceName[NamedAPIResource[Nature], Nature] = "nature"
const PalParkAreaResource ResourceName[NamedAPIResource[PalParkArea], PalParkArea] = "pal-park-area"
const PokeathlonStatResource ResourceName[NamedAPIResource[PokeathlonStat], PokeathlonStat] = "pokeathlon-stat"
const PokedexResource ResourceName[NamedAPIResource[Pokedex], Pokedex] = "pokedex"
const PokemonColorResource ResourceName[NamedAPIResource[PokemonColor], PokemonColor] = "pokemon-color"
const PokemonFormResource ResourceName[NamedAPIResource[PokemonForm], PokemonForm] = "pokemon-form"
const PokemonHabitatResource ResourceName[NamedAPIResource[PokemonHabitat], PokemonHabitat] = "pokemon-habitat"
const PokemonResource ResourceName[NamedAPIResource[Pokemon], Pokemon] = "pokemon"
const PokemonShapeResource ResourceName[NamedAPIResource[PokemonShape], PokemonShape] = "pokemon-shape"
const PokemonSpeciesResource ResourceName[NamedAPIResource[PokemonSpecies], PokemonSpecies] = "pokemon-species"
const RegionResource ResourceName[NamedAPIResource[Region], Region] = "region"
const StatResource ResourceName[NamedAPIResource[Stat], Stat] = "stat"
const SuperContestEffectResource ResourceName[APIResource[SuperContestEffect], SuperContestEffect] = "super-contest-effect"
const TypeResource ResourceName[NamedAPIResource[Type], Type] = "type"
const VersionGroupResource ResourceName[NamedAPIResource[VersionGroup], VersionGroup] = "version-group"
const VersionResource ResourceName[NamedAPIResource[Version], Version] = "version"
func (ResourceName[R, T]) Get ¶ added in v0.3.0
Get allows for the retrieval of a single instance of the desired resource.
func (ResourceName[R, T]) String ¶ added in v0.3.0
func (rn ResourceName[R, T]) String() string
type Stat ¶
type Stat struct { NamedIdentifier GameIndex int `json:"game_index"` // ID the games use for this stat. IsBattleOnly bool `json:"is_battle_only"` AffectingMoves MoveStatAffectSets `json:"affecting_moves"` AffectingNatures NatureStatAffectSets `json:"affecting_natures"` Characteristics []APIResource[Characteristic] `json:"characteristics"` // A list of characteristics that are set on a Pokémon when its highest base stat is this stat. MoveDamageClass *NamedAPIResource[MoveDamageClass] `json:"move_damage_class"` Names []Name `json:"names"` }
type SuperContestEffect ¶
type SuperContestEffect struct { Identifier Appeal int `json:"appeal"` FlavorTextEntries []FlavorText `json:"flavor_text_entries"` Moves []NamedAPIResource[Move] `json:"moves"` }
type Type ¶
type Type struct { NamedIdentifier DamageRelations TypeRelations `json:"damage_relations"` PastDamageRelations []TypeRelationsPast `json:"past_damage_relations"` GameIndices []GenerationGameIndex `json:"game_indices"` Generation NamedAPIResource[Generation] `json:"generation"` // The generation this type was introduced in. MoveDamageClass *NamedAPIResource[MoveDamageClass] `json:"move_damage_class"` Names []Name `json:"names"` Pokemon []TypePokemon `json:"pokemon"` Moves []NamedAPIResource[Move] `json:"moves"` }
type TypePokemon ¶
type TypePokemon struct { Slot int `json:"slot"` Pokemon NamedAPIResource[Pokemon] `json:"pokemon"` }
type TypeRelations ¶
type TypeRelations struct { NoDamageTo []NamedAPIResource[Type] `json:"no_damage_to"` HalfDamageTo []NamedAPIResource[Type] `json:"half_damage_to"` DoubleDamageTo []NamedAPIResource[Type] `json:"double_damage_to"` NoDamageFrom []NamedAPIResource[Type] `json:"no_damage_from"` HalfDamageFrom []NamedAPIResource[Type] `json:"half_damage_from"` DoubleDamageFrom []NamedAPIResource[Type] `json:"double_damage_from"` }
type TypeRelationsPast ¶
type TypeRelationsPast struct { Generation NamedAPIResource[Generation] `json:"generation"` // The last generation in which the referenced type had the listed damage relations. DamageRelations TypeRelations `json:"damage_relations"` }
type VerboseEffect ¶
type VerboseEffect struct { Effect string `json:"effect"` ShortEffect string `json:"short_effect"` Language NamedAPIResource[Language] `json:"language"` }
type Version ¶
type Version struct { NamedIdentifier Names []Name `json:"names"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` }
type VersionEncounterDetail ¶
type VersionEncounterDetail struct { Version NamedAPIResource[Version] `json:"version"` MaxChance int `json:"max_chance"` // Total % chance of all encounter potentials. EncounterDetails []Encounter `json:"encounter_details"` }
type VersionGameIndex ¶
type VersionGameIndex struct { GameIndex int `json:"game_index"` Version NamedAPIResource[Version] `json:"version"` }
type VersionGroup ¶
type VersionGroup struct { NamedIdentifier Order int `json:"order"` // Order for sorting. Almost by date of release, except similar versions are grouped together. Generation NamedAPIResource[Generation] `json:"generation"` MoveLearnMethods []NamedAPIResource[MoveLearnMethod] `json:"move_learn_methods"` Pokedexes []NamedAPIResource[Pokedex] `json:"pokedexes"` Regions []NamedAPIResource[Region] `json:"regions"` Versions []NamedAPIResource[Version] `json:"versions"` }
type VersionGroupFlavorText ¶
type VersionGroupFlavorText struct { Text string `json:"text"` // The localized name of the API resource in the referenced Language. Language NamedAPIResource[Language] `json:"language"` VersionGroup NamedAPIResource[VersionGroup] `json:"version_group"` // The version group which uses this flavor text. }
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cachetest
Package cachetest is a test suite for [pokeapi.Cache] implementations.
|
Package cachetest is a test suite for [pokeapi.Cache] implementations. |
cmd
|
|
gettergen
Command gettergen parses the pokeapi package and generates List* and Get* methods for the pokeapi.Client on types with the pokeapi.Identifier and pokeapi.NamedIdentifier directly embedded into them.
|
Command gettergen parses the pokeapi package and generates List* and Get* methods for the pokeapi.Client on types with the pokeapi.Identifier and pokeapi.NamedIdentifier directly embedded into them. |
Package iterator provides an Iterator type that manages page iteration for you - fetching the following pokeapi.GettableAPIResource and (if necessary) the next pokeapi.Page of resources.
|
Package iterator provides an Iterator type that manages page iteration for you - fetching the following pokeapi.GettableAPIResource and (if necessary) the next pokeapi.Page of resources. |
Package sprites provides types and helper methods for retrieving the sprite you need.
|
Package sprites provides types and helper methods for retrieving the sprite you need. |