-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
70 lines (62 loc) · 1.54 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
package main
import (
"flag"
"math/rand"
"net/http"
"net/url"
"time"
"github.com/Sirupsen/logrus"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"golang.org/x/crypto/acme/autocert"
"github.com/CovenantSQL/data-sharing-demo/api"
)
var (
devMode bool
)
func main() {
flag.BoolVar(&devMode, "dev", false, "run in dev mode")
flag.Parse()
logrus.SetLevel(logrus.DebugLevel)
rand.Seed(time.Now().UnixNano())
e := echo.New()
e.Use(middleware.CORS())
e.Use(middleware.Recover())
//e.Static("/", "frontend/client/dist")
e.POST("/apiv1/login", api.Login())
e.POST("/apiv1/logout", api.Logout())
e.GET("/apiv1/cargo", api.GetCargos())
e.POST("/apiv1/cargo", api.PostCargo())
e.PUT("/apiv1/cargo", api.PutCargo())
e.DELETE("/apiv1/cargo/:id", api.DeleteCargo())
e.POST("/apiv1/attach", api.Upload)
e.GET("/apiv1/attach/:file", api.Download)
e.GET("/apiv1/sql", api.GetCargoSql())
if devMode {
// debug proxy
url1, err := url.Parse("http://localhost:5000")
if err != nil {
logrus.Fatal(err)
}
targets := []*middleware.ProxyTarget{
{
URL: url1,
},
}
g := e.Group("/")
g.Use(middleware.Proxy(middleware.NewRoundRobinBalancer(targets)))
e.Start(":8081")
} else {
e.AutoTLSManager.Cache = autocert.DirCache("./cert")
e.GET("/", func(c echo.Context) error {
return c.HTML(http.StatusOK, `
<h1>Welcome to Echo!</h1>
<h3>TLS certificates automatically installed from Let's Encrypt :)</h3>
`)
})
e.StartTLS(":7790",
"./cert/gridb.io/gridb.io.cer",
"./cert/gridb.io/gridb.io.key",
)
}
}