-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
104 lines (81 loc) · 2.41 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/redirect/v2"
"github.com/joho/godotenv"
"gitlab.com/hardcake/eyesuite/controller"
"gitlab.com/hardcake/eyesuite/middleware"
"gitlab.com/hardcake/eyesuite/server"
"gitlab.com/hardcake/eyesuite/service"
"gitlab.com/hardcake/eyesuite/service/storage"
"gitlab.com/hardcake/eyesuite/service/tesseract"
"gitlab.com/hardcake/eyesuite/service/token"
"log"
)
var tes tesseract.Tesseract
var tok token.Token
var sto storage.Storage
func init() {
// load env module
err := godotenv.Load()
if err != nil {
log.Fatal(err)
}
// Get environment variables
cts := service.GetEnv()
// load services and service cors
tes = tesseract.NewTesseract()
tok = token.NewToken(cts.AccessSecret, cts.RefreshSecret)
sto = storage.NewStorage("db", "6379", "")
//sto = storage.NewStorage("localhost", "6379", "")
preLoadConfig()
preProfile()
prePlugin()
preLoadAdminUser()
}
func main() {
s := service.NewService(sto, tes, tok)
m := middleware.NewMiddleware(s)
c := controller.NewController(s)
app := fiber.New()
app.Use(redirect.New(redirect.Config{
Rules: map[string]string{
"/help": "/",
"/settings/connection": "/",
"/settings/plugins": "/",
"/settings/profiles": "/",
"/settings/users": "/",
},
StatusCode: 301,
}))
// Serve static content
app.Static("/", "./frontend/build")
// JWT management
app.Post("/api/login", c.Login)
app.Post("/api/logout", m.Auth, c.Logout)
app.Post("/api/refresh", m.Auth, c.Refresh)
// Post results to Netsuite
app.Post("/api/postImage", m.Auth, c.PostImage)
// Manage Users
app.Get("/api/users", m.Auth, c.ReadUsers)
app.Post("/api/users", m.Auth, m.Admin, c.UpsertUsers)
// Manage Configuration
app.Get("/api/config", m.Auth, c.ReadConfig)
app.Post("/api/config", m.Auth, m.Admin, c.UpsertConfig)
// Manage Profiles
app.Get("/api/profiles", m.Auth, c.ReadProfiles)
app.Post("/api/profiles", m.Auth, m.Admin, c.UpsertProfiles)
// Manage Plugins
app.Get("/api/plugins", m.Auth, c.ReadPlugins)
app.Post("/api/plugins", m.Auth, m.Admin, c.UpsertPlugins)
// Read image with Tesseract
app.Post("/api/plugins/readText", m.Auth, c.ReadImageText)
// Read barcodes
app.Post("/api/plugins/readBarcode", m.Auth, c.ReadImageBarcode)
// Read QR codes
app.Post("/api/plugins/readQr", m.Auth, c.ReadImageQr)
// Api root
app.Get("/api", c.ApiHome)
// Start!!
server.Start(app)
}