Features
- All Riot APIs implemented
- Riot Account
- League of Legends
- Teamfight Tactics
- Valorant
- Legends of Runeterra
- Cache
- Rate Limiting
Caching and Rate limiting is in an early stage, they are in-memory only for now.
Todo
- Review the cache and rate limiting implementation
- Add a way to define a custom TTL per endpoint method
- Add Data Dragon support
- Add Helper Methods (e.g.: GetChampion or GetSummoner inside a match response)
Installation
To install equinox you can either import it in a package:
import "github.com/Kyagara/equinox"
and run go get
without any parameters, or, if you want to use the latest version from this repo, you can use the following command:
go get github.com/Kyagara/equinox@master
Usage
To access the diferent parts of the Riot Games API, create a new instance of the Equinox client:
client, err := equinox.NewClient("RIOT_API_KEY")
A client without a configuration struct comes with the default options:
config := &api.EquinoxConfig{
Key: "RIOT_API_KEY", // The API Key provided as a parameter.
Cluster: api.AmericasCluster, // Riot API cluster, use the nearest cluster. Options: AmericasCluster, EuropeCluster, AsiaCluster.
LogLevel: api.FatalLevel, // The logging level, the FatalLevel provided effectively disables logging.
Timeout: 10, // http.Client timeout in seconds.
TTL: 120, // TTL for cache in seconds, 0 disables caching.
Retry: true, // Retry if the API returns a 429 response.
RateLimit: true // If rate limit is enabled or not
}
A configuration struct can be used to create a custom Client using equinox.NewClientWithConfig()
.
Now you can access different games endpoints by their abbreviations, provided you have access to them. For example:
// This method uses a lol.Region. Can be accessed with a Development key.
summoner, err := client.LOL.Summoner.ByName(lol.BR1, "Loveable Senpai")
// The client.Cluster will be used as the region. Can be accessed with a Development key.
account, err := client.Riot.Account.ByPUUID("puuid")
// This method uses a val.Shard. May not be available in your policy.
recentMatches, err := client.VAL.Match.Recent(val.BR, val.CompetitiveQueue)
Example
package main
import (
"fmt"
"github.com/Kyagara/equinox"
"github.com/Kyagara/equinox/lol"
)
func main() {
// For custom configurations, you can use NewClientWithConfig(),
// you will need to provide an api.EquinoxConfig{} object.
client, err := equinox.NewClient("RIOT_API_KEY")
if err != nil {
fmt.Println("error creating client: ", err)
return
}
// Get this week's champion rotations.
rotation, err := client.LOL.Champion.Rotations(lol.BR1)
if err != nil {
fmt.Println("error retrieving champion rotations: ", err)
return
}
fmt.Printf("%+v\n", rotation)
// &{FreeChampionIDs:[17 43 56 62 67 79 85 90 133 145 147 157 201 203 245 518]
// FreeChampionIDsForNewPlayers:[222 254 427 82 131 147 54 17 18 37]
// MaxNewPlayerLevel:10}
}
About
This is my first time developing and publishing an API client, I started this project to learn more about Golang and ended up loving the developer experience using Go, after noticing there wasn't any 'all-in-one' type of client for all Riot Games API endpoints I decided to challenge myself and do it.
I learned a lot about how API clients work and I am constantly changing the project as I test and learn new things, however, as the project approaches a more stable version, I am avoiding doing any breaking changes.
Please, always check the commit messages before a new release to check if there was any breaking change introduced.
Disclaimer
Equinox isn't endorsed by Riot Games and doesn't reflect the views or opinions of Riot Games or anyone officially involved in producing or managing Riot Games properties. Riot Games, and all associated properties are trademarks or registered trademarks of Riot Games, Inc.
License
This project is licensed under the MIT license.
The internal/client.go
file contains code from golio. golio is also licensed under MIT.