-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.go
44 lines (38 loc) · 913 Bytes
/
users.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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"strings"
)
type UserInfo struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Github string `json:"github,omitempty"`
Role string `json:"role,omitempty"`
Course int `json:"course"`
Faculty string `json:"faculty,omitempty"`
Group int `json:"group,omitempty"`
Description string `json:"description"`
Comment string `json:"comment"`
}
var users = make(map[string]UserInfo)
func loadUsers() {
data, err := ioutil.ReadFile("./data/users.json")
if err != nil {
log.Fatal(err)
return
}
var arr []UserInfo
err = json.Unmarshal(data, &arr)
if err != nil {
log.Fatal(err)
return
}
for _, u := range arr {
i := strings.LastIndex(u.Github, "/")
login := strings.ToLower(u.Github[i+1:])
users[strings.ToLower(u.Github)] = u
users[login] = u
}
}