-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
44 lines (36 loc) · 935 Bytes
/
server.go
File metadata and controls
44 lines (36 loc) · 935 Bytes
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
package main
import (
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/skratchdot/open-golang/open"
"strconv"
)
func createAuth(cred []string) echo.MiddlewareFunc {
return middleware.BasicAuth(func(username, password string, c echo.Context) (error, bool) {
if username == cred[0] && password == cred[1] {
return nil, true
}
return nil, false
})
}
func startServer(cfg serverConfig) {
port := strconv.Itoa(cfg.port)
e := echo.New()
if cfg.debug {
e.Use(middleware.Logger())
}
e.Use(middleware.Recover())
e.GET("/list", handleAll)
admin := e.Group("/admin")
admin.Use(createAuth(cfg.credentials))
admin.GET("/pack", handlePack)
admin.POST("/add", handleAdd)
admin.POST("/edit", handleEdit)
admin.GET("/delete", handleDelete)
e.Static("/plugins", "plugins")
e.Static("/", "public")
if cfg.browser {
open.Run("http://localhost:" + port + "/")
}
e.Start(":" + port)
}