From 8acdb78f0035b2c126b2a082fe91403c864f770d Mon Sep 17 00:00:00 2001 From: Odyssey Date: Thu, 19 Jan 2023 16:08:09 +0100 Subject: [PATCH] something Signed-off-by: Odyssey --- main.go | 24 ++---------------------- utils/main.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 utils/main.go diff --git a/main.go b/main.go index b045397..3a43e27 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/ProjectSegfault/publapi/pages" + "github.com/ProjectSegfault/publapi/utils" "github.com/gofiber/fiber/v2" log "github.com/sirupsen/logrus" "github.com/spf13/viper" @@ -31,27 +32,6 @@ type Userinfo struct { 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 { filename := "/home/" + username + "/meta-info.env" _, error := os.Stat(filename) @@ -116,7 +96,7 @@ func main() { return c.SendStatus(fiber.StatusInternalServerError) } usersonlinestr := string(usersonline) - usersonlinededup := Dedup(usersonlinestr) + usersonlinededup := utils.Dedup(usersonlinestr) outputa := int(strings.Count(usersonlinededup, " ")) var output int output = outputa + 1 diff --git a/utils/main.go b/utils/main.go new file mode 100644 index 0000000..3fc48d2 --- /dev/null +++ b/utils/main.go @@ -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 +}