add error handling for reading configuration #1
@ -55,7 +55,7 @@ func (a ByAdminAndName) Less(i, j int) bool {
|
||||
func (a ByAdminAndName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
func UserError(message string, username string, err error) {
|
||||
log.Error("error", message, log.Any("err", err), "username", username)
|
||||
log.Error("message", message, log.Any("err", err), "username", username)
|
||||
}
|
||||
|
||||
func userData(username, usersonline, ops string) UserInfo {
|
||||
@ -79,7 +79,7 @@ func userData(username, usersonline, ops string) UserInfo {
|
||||
_, error := os.Stat(filename)
|
||||
if error != nil {
|
||||
if os.IsNotExist(error) {
|
||||
log.Error(username + " does not have a meta-info.toml")
|
||||
UserError("user doesn't have a meta-info.toml", username, error)
|
||||
var user UserInfo
|
||||
user.Name = username
|
||||
user.Created, _ = strconv.Atoi(crdstr)
|
||||
@ -98,7 +98,7 @@ func userData(username, usersonline, ops string) UserInfo {
|
||||
}
|
||||
viper.SetConfigFile(filename)
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
log.Error("message", "Couldn't read a users meta-info.toml file.", "error", log.Any("err", err), "user", username)
|
||||
log.Error("message", "couldn't read a users meta-info.toml file.", "error", log.Any("err", err), "user", username)
|
||||
user := UserInfo{
|
||||
Name: username,
|
||||
}
|
||||
@ -175,15 +175,14 @@ func UsersPage(c *fiber.Ctx) error {
|
||||
log.Error("couldn't get all users", "error", log.Any("err", err2))
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
userstr := string(users)
|
||||
userstr2 := strings.TrimSuffix(userstr, "\n")
|
||||
usersarr := strings.Split(userstr2, "\n")
|
||||
userstr := strings.TrimSuffix(string(users), "\n")
|
||||
usersarr := strings.Split(userstr, "\n")
|
||||
// Fill user info
|
||||
var userInfoStruct []UserInfo
|
||||
var userInfoArray []UserInfo
|
||||
for i := 0; i < len(usersarr); i++ {
|
||||
uname := string(usersarr[i])
|
||||
userInfoStruct = append(
|
||||
userInfoStruct,
|
||||
userInfoArray = append(
|
||||
userInfoArray,
|
||||
userData(
|
||||
uname,
|
||||
strings.TrimSuffix(usersOnlineDedup, "\n"),
|
||||
@ -191,11 +190,11 @@ func UsersPage(c *fiber.Ctx) error {
|
||||
),
|
||||
)
|
||||
}
|
||||
sort.Sort(ByAdminAndName(userInfoStruct))
|
||||
sort.Sort(ByAdminAndName(userInfoArray))
|
||||
data := UserStruct{
|
||||
Status: c.Response().StatusCode(),
|
||||
Online: output,
|
||||
Users: userInfoStruct,
|
||||
Users: userInfoArray,
|
||||
Total: int(strings.Count(userstr, "\n")),
|
||||
}
|
||||
return c.JSON(data)
|
||||
|
@ -31,7 +31,7 @@ There is a Matrix chat room for everything about the Pubnix. You can ask for hel
|
||||
There is a password for Pubnix-related things in your user directory, you can run cat ~/pass to see it. We recommend to store it somewhere else and delete the file.
|
||||
You also get access to our public authentik instance, which allows you to sign up to many Project Segfault services with your Pubnix account. You can find it at https://auth.p.projectsegfau.lt, log in and you will be able to see a list of applications you can use authentik to log in with.
|
||||
|
||||
If you ever get confused or have no idea what to do, we have some articles on our wiki at https://wiki.projectsegfau.lt/index.php?title=Category:Pubnix.
|
||||
If you ever get confused or have no idea what to do, we have some articles on our wiki at https://wiki.projectsegfau.lt/t/pubnix.
|
||||
You can also give us suggestions at this Vikunja page: https://pubnixtodo.p.projectsegfau.lt.
|
||||
We hope you have enough freedom to do what you want. You are limited to 10GB of storage however.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user