34 lines
565 B
Go
34 lines
565 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func getUsers42CTF() (map[string]int, error) {
|
|
var jsonParse map[string]int
|
|
|
|
client := http.Client{ Timeout: time.Second * 2}
|
|
req, err := http.NewRequest(http.MethodGet, api, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res, err := client.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer res.Body.Close()
|
|
body, err := io.ReadAll(res.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = json.Unmarshal([]byte(body), &jsonParse)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return jsonParse, nil
|
|
}
|
|
|