-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (39 loc) · 771 Bytes
/
main.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
44
45
46
47
48
49
50
51
package main
import (
"encoding/json"
"io"
"net/http"
"os"
)
type Profile struct {
UUID string `json:"id"`
Name string `json:"name"`
}
const PROFILE_ENDPOINT = "https://api.mojang.com/users/profiles/minecraft/"
func main() {
args := os.Args[1:]
if len(args) == 0 {
println("Usage: mcl <username>")
os.Exit(1)
return
}
username := args[0]
profile := getProfile(username)
if profile == nil || profile.UUID == "" {
println("Profile not found")
os.Exit(1)
return
}
printInfo(profile)
}
func getProfile(query string) *Profile {
res, err := http.Get(PROFILE_ENDPOINT + query)
if err != nil {
return nil
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
var profile Profile
json.Unmarshal(body, &profile)
return &profile
}