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
727 B
Go

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