You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
website/utenti.go

42 lines
729 B
Go

2 years ago
package website
import (
"encoding/json"
2 years ago
"log"
2 years ago
"os"
)
type UserInfo struct {
3 years ago
Uid string `json:"uid"`
Nome string `json:"nome"`
Cognome string `json:"cognome"`
Tags []string `json:"tags"`
IsMacchinista bool `json:"macchinista,omitempty"`
}
2 years ago
type ListaUtentiService interface {
GetUtenti() ([]UserInfo, error)
}
3 years ago
type JsonFileListaUtenti struct {
2 years ago
Path string
}
3 years ago
func (j *JsonFileListaUtenti) GetUtenti() ([]UserInfo, error) {
var users []UserInfo
2 years ago
usersJsonData, err := os.ReadFile(j.Path)
if err != nil {
return nil, err
}
if err := json.Unmarshal(usersJsonData, &users); err != nil {
return nil, err
}
2 years ago
log.Printf("Loaded list utenti with %d users", len(users))
return users, nil
}