-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_character_metadata_from_indexer.go
43 lines (36 loc) · 1.32 KB
/
get_character_metadata_from_indexer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package indexer
import (
"encoding/json"
"fmt"
"github.com/Crossbell-Box/OperatorSync/app/worker/config"
"github.com/Crossbell-Box/OperatorSync/app/worker/global"
"github.com/Crossbell-Box/OperatorSync/app/worker/types"
"net/http"
)
type characterMetadataIndexerResponse struct {
Metadata types.CharacterMetadata `json:"metadata"`
// Ignore other fields
}
func GetCharacterMetadataFromIndexer(characterIdStr string) (*types.CharacterMetadata, error) {
// Prepare request
req, err := http.NewRequest("GET", fmt.Sprintf("%s/v1/characters/%s", config.Config.CrossbellIndexer, characterIdStr), nil)
if err != nil {
global.Logger.Errorf("Failed to prepare request for get character data (%s) from indexer with error: %s", characterIdStr, err.Error())
return nil, err
}
// Execute request
res, err := (&http.Client{}).Do(req)
if err != nil {
global.Logger.Errorf("Failed to execute request for get character data (%s) from indexer with error: %s", characterIdStr, err.Error())
return nil, err
}
// Parse response
var resBody characterMetadataIndexerResponse
err = json.NewDecoder(res.Body).Decode(&resBody)
if err != nil {
global.Logger.Errorf("Failed to parse response for get character data (%s) from indexer with error: %s", characterIdStr, err.Error())
return nil, err
}
// Return
return &resBody.Metadata, nil
}