-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (42 loc) · 824 Bytes
/
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
package main
import (
"flag"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
"github.com/labstack/echo/middleware"
"log"
)
const (
staticUrl = "/static"
)
var (
httpAddr = flag.String("http", defaultAddr, "Listen for HTTP connections on this address.")
)
func init() {
flag.Parse()
if err := cacheTemplates([]string{
"templates/home.tmpl",
}); err != nil {
log.Fatal(err)
}
}
func app() *echo.Echo {
e := echo.New()
// Default Middlewares
e.Use(middleware.Logger())
e.Use(middleware.Gzip())
e.Use(middleware.Recover())
// Groups
h := e.Group("")
s := e.Group(staticUrl)
h.Get("/", home())
// Static
s.Get("/:folder/:file", serveFile())
s.Get("/favicon.ico", serveFavicon())
return e
}
func main() {
e := app()
// Start server
e.Run(standard.New(*httpAddr))
}