mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-14 05:39:52 +01:00
Respect rate limit of jikan
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
@@ -91,11 +92,7 @@ func GetUserData(username string) (*User, []byte, error) {
|
||||
err = nil
|
||||
dataJikan, err := GetDataJikan(userApiJikan + username)
|
||||
if err != nil {
|
||||
// retry bcs Jikan big baka
|
||||
dataJikan, err = GetDataJikan(userApiJikan + username)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
if strings.Contains(string(dataJikan), "BadResponseException") {
|
||||
return nil, nil, fmt.Errorf("user not found: %s", username)
|
||||
@@ -194,6 +191,8 @@ func GetDataMal(apiAddr string) ([]byte, error) {
|
||||
|
||||
func GetDataJikan(apiAddr string) ([]byte, error) {
|
||||
var body []byte
|
||||
ctx := context.Background()
|
||||
jikanLimiter.Wait(ctx)
|
||||
statusCode, body, err := fasthttp.Get(body, *jikanApiBaseUri+apiAddr)
|
||||
if statusCode != fasthttp.StatusOK {
|
||||
return body, fmt.Errorf("unexpected response code: %s %d", *jikanApiBaseUri+apiAddr, statusCode)
|
||||
|
||||
Reference in New Issue
Block a user