something

Signed-off-by: Odyssey <odyssey346@disroot.org>
This commit is contained in:
Odyssey 2023-01-19 16:08:09 +01:00
parent c54ce2b46b
commit 8acdb78f00
2 changed files with 28 additions and 22 deletions

24
main.go
View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
"github.com/ProjectSegfault/publapi/pages" "github.com/ProjectSegfault/publapi/pages"
"github.com/ProjectSegfault/publapi/utils"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -31,27 +32,6 @@ type Userinfo struct {
Loc string `json:"loc"` Loc string `json:"loc"`
} }
func Dedup(input string) string {
unique := []string{}
words := strings.Split(input, " ")
for _, word := range words {
if contains(unique, word) {
continue
}
unique = append(unique, word)
}
return strings.Join(unique, " ")
}
func contains(strs []string, str string) bool {
for _, s := range strs {
if s == str {
return true
}
}
return false
}
func userdata(username, usersonline string) Userinfo { func userdata(username, usersonline string) Userinfo {
filename := "/home/" + username + "/meta-info.env" filename := "/home/" + username + "/meta-info.env"
_, error := os.Stat(filename) _, error := os.Stat(filename)
@ -116,7 +96,7 @@ func main() {
return c.SendStatus(fiber.StatusInternalServerError) return c.SendStatus(fiber.StatusInternalServerError)
} }
usersonlinestr := string(usersonline) usersonlinestr := string(usersonline)
usersonlinededup := Dedup(usersonlinestr) usersonlinededup := utils.Dedup(usersonlinestr)
outputa := int(strings.Count(usersonlinededup, " ")) outputa := int(strings.Count(usersonlinededup, " "))
var output int var output int
output = outputa + 1 output = outputa + 1

26
utils/main.go Normal file
View File

@ -0,0 +1,26 @@
package utils
import (
"strings"
)
func Dedup(input string) string {
unique := []string{}
words := strings.Split(input, " ")
for _, word := range words {
if contains(unique, word) {
continue
}
unique = append(unique, word)
}
return strings.Join(unique, " ")
}
func contains(strs []string, str string) bool {
for _, s := range strs {
if s == str {
return true
}
}
return false
}