-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (34 loc) · 757 Bytes
/
Copy pathmain.go
File metadata and controls
42 lines (34 loc) · 757 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
package main
import (
"flag"
"fmt"
"net/http"
"time"
"github.com/deepu7d/go-api/internal/app"
"github.com/deepu7d/go-api/internal/routes"
)
func main() {
// port that I can take from CLI as a flag
var port int
flag.IntVar(&port, "port", 8080, "go backend server port")
flag.Parse()
app, err := app.NewApplication()
if err != nil {
panic(err)
}
defer app.DB.Close()
// route handler
r := routes.SetupRoutes(app)
server := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: r,
IdleTimeout: time.Minute,
ReadTimeout: 10 * time.Second,
WriteTimeout: 30 * time.Second,
}
app.Logger.Printf("Server Started on PORT: %d\n", port)
err = server.ListenAndServe()
if err != nil {
app.Logger.Fatal(err)
}
}