-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (34 loc) · 901 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
package main
import (
"flag"
"log"
"github.com/snowboardit/usda-zones-api/handlers"
"github.com/snowboardit/usda-zones-api/lib/data"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
)
var (
port = flag.String("port", ":3000", "Port to listen on")
prod = flag.Bool("prod", false, "Enable prefork in production")
)
func main() {
// Parse cmd line flags
flag.Parse()
// Create new Fiber app
app := fiber.New(fiber.Config{
Prefork: *prod, // go run app.go -prod
})
// Setup middleware
app.Use(recover.New())
app.Use(logger.New())
// Setup data
data.Store = data.Load()
// Create api group
api := app.Group("/api")
api.Get("/zip/:code", handlers.GetByZip)
// Handle not founds
app.Use(handlers.NotFound)
// Listen on port 3000
log.Fatal(app.Listen(*port)) // go run app.go -port=:3000
}