-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
42 lines (38 loc) · 1.23 KB
/
user.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
package main
import (
"encoding/json"
"fmt"
)
// User type.
type User struct {
Nickname string `json:"nickname"`
Description string `json:"description"`
Doing string `json:"doing"`
Level float64 `json:"level"`
Avatar string `json:"avatar"`
}
// GetUserInfo is a function.
func GetUserInfo(id string) User {
pageBytes := Scrap("https://api.codemao.cn/api/user/info/detail/" + id)
data := make(map[string]interface{})
json.Unmarshal(pageBytes, &data)
userInfo := data["data"].(map[string]interface{})["userInfo"].(map[string]interface{})["user"].(map[string]interface{})
user := User{
Nickname: userInfo["nickname"].(string),
Description: userInfo["description"].(string),
Doing: userInfo["doing"].(string),
Level: userInfo["level"].(float64),
Avatar: userInfo["avatar"].(string),
}
return user
}
// NotifyUserInfo can print the info.
func NotifyUserInfo(u User) {
fmt.Printf("Name:\t%s\n", u.Nickname)
fmt.Println("Description: --------------------------------------")
fmt.Printf("%s\n", u.Description)
fmt.Println("---------------------------------------------------")
fmt.Printf("Doing:\t%s\n", u.Doing)
fmt.Printf("Level:\t%f\n", u.Level)
fmt.Printf("Logo URL:\t%s\n", u.Avatar)
}