-
-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Kevin Souza edited this page May 8, 2024
·
9 revisions
Get the library:
go get github.com/Kyagara/equinox/v2 # or, for the latest version: go get github.com/Kyagara/equinox@main
Create a new instance of the equinox client:
client, err := equinox.NewClient("RGAPI...")
// or, for a client without Cache and custom http.Client:
config := api.EquinoxConfig{
Key: "RGAPI...",
Retry: DefaultRetry(),
Logger: DefaultLogger(),
}
httpClient := &http.Client{Timeout: 15 * time.Second}
client, err := equinox.NewCustomClient(config, httpClient, nil, ratelimit.NewInternalRateLimit(0.99, time.Second))
The default client configuration comes with these options set:
- Key: The provided Riot API key.
- HTTPClient: Default http.Client.
- Cache: BigCache with a TTL of 4 minutes.
- RateLimit: InternalRateLimit with a limit usage factor of 0.99 and interval overhead of 1 second.
- Logger: Logger with zerolog.WarnLevel. Will log if rate limited or when retrying a request.
- Retry: Will retry a request a maximum of 3 times with a jitter of 500 milliseconds.
Using different endpoints:
// Contexts without a deadline will block if rate limited, waiting for the rate limited buckets to reset.
// If a deadline is set, there will be checks done before any block to see if waiting would exceed that deadline.
//
// You can also pass some Values to the ctx, 'api.Revalidate' for example can be used to revalidate the cache, forcing an update to it.
ctx := context.Background()
// This method uses an api.RegionalRoute. Can be accessed with a Development key.
match, err := client.LOL.MatchV5.ByID(ctx, api.AMERICAS, "BR1_2...")
// This method uses an val.PlatformRoute. May not be available in your policy.
matches, err := client.VAL.MatchV1.Recent(ctx, val.BR, "competitive")
// Interacting with the cache.
data, err := client.Cache.Get("https://...")
err := client.Cache.Set("https://...", data)
// Using ExecuteBytes which returns []byte but skips checking cache.
logger := client.Internal.Logger("LOL_StatusV4_Platform")
urlComponents := []string{"https://", lol.BR1, api.RIOT_API_BASE_URL_FORMAT, "/lol/status/v4/platform-data"}
req, err := client.Internal.Request(ctx, logger, http.MethodGet, urlComponents, "lol-status-v4.getPlatformData", nil)
data, err := client.Internal.ExecuteBytes(ctx, req)
equinox started as a way for me to learn go, many projects helped me to understand the inner workings of an API client and go itself, here are some of them, check them out.
Projects not written in go:
A rewrite of Riven's code generation is used in equinox.
If cloning the project, make sure to have a go.work
file in the root of the project, if you don't, you will get an error when trying to run go generate
.
go 1.21
use (
.
./codegen
)
If you have any questions, feel free to open an issue or contact me.