-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.go
34 lines (30 loc) · 863 Bytes
/
webserver.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
package main
import (
configModels "github.com/goharbor/ldaputils/dao/models"
"github.com/goharbor/ldaputils/handlers"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func WebServer() {
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
if err != nil {
panic("failed to connect to database")
}
db.AutoMigrate(&configModels.LdapConfig{})
// Echo instance
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Routes
e.File("/", "public/index.html")
e.File("/vue.js", "public/vue.js")
e.GET("/configs", handlers.GetConfigs(db))
e.PUT("/configs", handlers.PutConfig(db))
e.DELETE("/configs/:id", handlers.DeleteConfig(db))
e.POST("/testconfig/:id", handlers.TestingConfig(db))
// Start server
e.Logger.Fatal(e.Start(":8080"))
}