-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
69 lines (55 loc) · 1.47 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"log"
"os"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/monitor"
)
func main() {
if len(os.Args) > 1 {
argsStr := strings.Join(os.Args[1:], " ")
done := ProcessCommand(argsStr)
if !done {
log.Fatal("Invalid Command")
os.Exit(1)
} else {
log.Println("Done")
os.Exit(0)
}
}
SetupCLIHandler()
app := fiber.New()
app.Use(logger.New())
app.Use(AuthenticateMiddleware)
app.Get("/", Health)
app.Get("/ocs/v2.php/cloud/capabilities", CapabilitiesAPI)
notesAPIs := app.Group("/index.php/apps/notes/api/v1/notes")
notesAPIs.Get("/", GetNotes)
notesAPIs.Post("/", CreateNote)
notesAPIs.Put("/:id", UpdateNote)
notesAPIs.Delete("/:id", DeleteNote)
app.Get("/metrics", monitor.New(monitor.Config{Title: "Quillnote Server Stats"}))
app.All("/*", NotFound)
log.Fatal(app.Listen(":3000"))
}
func _(UserPassListString string) (map[string]string, error) {
if UserPassListString == "" {
return nil, errors.New("user list is empty")
}
UserPassList := strings.Split(UserPassListString, ",")
if len(UserPassList) == 0 {
return nil, errors.New("user list is empty")
}
Users := make(map[string]string)
for _, UserPass := range UserPassList {
UserPassSplit := strings.Split(UserPass, ":")
if len(UserPassSplit) != 2 {
return nil, errors.New("user list is invalid")
}
Users[UserPassSplit[0]] = UserPassSplit[1]
}
return Users, nil
}