-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
executable file
·32 lines (26 loc) · 915 Bytes
/
app.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
package main
import (
"log"
"net/http"
"user-management-api-service/Routes"
"user-management-api-service/internal/config"
"github.com/go-chi/chi"
)
//Startup function
func main() {
configuration, err := config.GetEnv()
if err != nil {
log.Panicln("Configuration error", err)
}
router := Routes.SetRoutes()
walkFunc := func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
log.Printf("%s %s\n", method, route) // Walk and print out all routes
return nil
}
if err := chi.Walk(router, walkFunc); err != nil {
log.Printf("Logging err: %s\n", err.Error()) // panic if there is an error
}
//configuration type has two fields: Constants(PORT AND (URL + DBNAME)) & Database reference
log.Println("Serving application at PORT :" + configuration.Constants.PORT)
log.Fatal(http.ListenAndServe(":"+configuration.Constants.PORT, router))
}