PokeGo is an Golang API wrapper for the PokéAPI v2.
PokeGo can be installed using the following command:
go get github.com/JoshGuarino/PokeGo
There are two options for using PokeGo. You can either use the main client or create individual resource groups seperately. The main client will initialize all resource groups for you. If you choose to use individual resource groups, you will need to initialize each group separately.
package main
import (
pokego "github.com/JoshGuarino/PokeGo/pkg"
)
func main() {
client := pokego.NewClient()
}
package main
import (
"github.com/JoshGuarino/PokeGo/pkg/resources/pokemon"
)
func main() {
pokemonGroup := pokemon.NewPokemonGroup()
}
Below is a list of all the resource groups available in PokeGo. Each resource group has a set of methods that can be used to interact with the PokeAPI.
PokeGo supports pagination for list endpoints. The GetPokemonList()
method is an example of a list endpoint that supports pagination.
The method takes two arguments, limit
and offset
. The limit
argument is the number of results to return and the offset
argument
is the number of results to skip. Both arugments are required as Golang does not support default arguments.
// Main client example returning the first page of 20 results
limit, offset := 20, 0
pokemonList, err := client.Pokemon.GetPokemonList(limit, offset)
// Individual resource group example returning the second page of 20 results
limit, offset := 20, 20
pokemonList, err := pokemonGroup.GetPokemonList(limit, offset)
Single resource endpoints are used to retrieve a single resource from the PokeAPI. Named resources can be accessed using the name or ID of the resource. Non named resources can be accessed using only the ID of the resource.
// Main client example
pokemon, err := client.Pokemon.GetPokemon("charmander")
// Individual resource group example
pokemon, err := pokemonGroup.GetPokemon("charmander")
PokeGo uses a simple in-memory cache to store API responses. This is to reduce the number of requests made to the PokeAPI. The cache is set to expire after 24 hours by default, as resources in the PokeAPI are mostly static. You are able to disable the cache or change the expiration time of a cached resource. I would reccommend against disabling it as it will result in a large number of requests to the PokeAPI and may result in rate limiting. For more information on the cache, see the CACHE.md documentation.
The environment package manages the API base URL and domain. By default, the environment is set to production. For more information on the environment, see the ENVIRONMENT.md documentation.
The logger package provides a simple and flexible logging mechanism for your application.
It supports various log levels and allows you to track messages.
It is a wrapper around the https://github.com/charmbracelet/log
library.
For more information on the logger, see the LOGGER.md documentation.
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements. See the CONTRIBUTING.md file for more information.
PokeGo is licensed under the BSD 3-Clause License.