-
-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Kevin Souza edited this page Apr 26, 2024
·
9 revisions
Get the library:
go get github.com/Kyagara/equinox # 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:
config := api.EquinoxConfig{
Key: "RGAPI...",
HTTPClient: &http.Client{
Timeout: 15 * time.Second,
},
Cache: nil,
RateLimit: ratelimit.NewInternalRateLimit(0.99, time.Second),
Retry: DefaultRetry(),
Logger: DefaultLogger(),
}
client, err := equinox.NewClientWithConfig(config)
The default client configuration from DefaultConfig("RGAPI...")
comes with these options set:
- Key: The provided Riot API key.
-
HTTPClient:
http.Client
with a timeout of 15 seconds. -
Cache:
BigCache
with an eviction time of 4 minutes. - RateLimit: Internal rate limiter with a limit usage factor of 0.99 and interval overhead of 1 second.
-
Logger: api.Logger object with
zerolog.WarnLevel
. Will log in JSON if rate limited or when retrying a request (before waiting). - Retry: api.Retry object with a limit of 3 and 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.
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 ExecuteRaw which returns []byte but skips checking cache.
l := 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, l, http.MethodGet, urlComponents, "", nil)
data, err := client.Internal.ExecuteRaw(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.