-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (47 loc) · 1.22 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
package main
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/tkc/go-echo-server-sandbox/config"
"github.com/tkc/go-echo-server-sandbox/handler"
userModel "github.com/tkc/go-echo-server-sandbox/models/user"
"github.com/tkc/go-echo-server-sandbox/template"
"golang.org/x/crypto/acme/autocert"
)
func getStatus(c echo.Context) error {
message := `
____ __
/ __/___/ / ___
/ _// __/ _ \/ _ \
/___/\__/_//_/\___/
`
return c.String(http.StatusOK, message)
}
func main() {
e := echo.New()
u := userModel.User{}
h := handler.CreateHandler(u)
template := template.GetTemplate()
e.Renderer = &template
e.Use(middleware.Recover())
e.Use(middleware.Logger())
e.Static("/css", "./public/css")
e.Static("/dist", "./public/dist")
e.GET("/", getStatus)
e.GET("template", h.GetTemplate)
e.GET("/user/:id", h.Get)
e.POST("/user", h.Create)
e.PUT("/user", h.Update)
e.DELETE("/user", h.Delete)
if config.IsProd() {
e.AutoTLSManager.Cache = autocert.DirCache("./.cache")
e.Pre(middleware.HTTPSRedirect())
go func(c *echo.Echo) {
e.Logger.Fatal(e.Start(":80"))
}(e)
e.Logger.Fatal(e.StartAutoTLS(":443"))
} else {
e.Logger.Fatal(e.Start(config.GetPort()))
}
}