-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (55 loc) · 2.01 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
61
62
63
64
65
66
package main
import (
"log"
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/render"
"time"
"rest"
"customlogger"
"config"
//"filestore"
)
//var LOGGER *log.Logger=nil
var DEFAULT_CONFIG_FILE_PATH="C:\\git\\DSOM-ADE\\fluent-heartbeat-service\\app.properties"
var err error
var CONFIG config.Config
func Routes() *chi.Mux {
router := chi.NewRouter()
router.Use(
render.SetContentType(render.ContentTypeJSON), // Set content-Type headers as application/json
middleware.Logger, // Log API request calls
//middleware.DefaultCompress, // Compress results, mostly gzipping assets and json
middleware.RedirectSlashes, // Redirect slashes to no slash URL versions
middleware.Recoverer, // Recover from panics without crashing server
)
router.Route("/v1", func(r chi.Router) {
r.Mount("/api/agent", rest.Routes())
})
return router
}
func main() {
log.Printf("Staring app...")
logger:=customlogger.GetInstance()
router := Routes()
CONFIG,err:=config.LoadConfig(DEFAULT_CONFIG_FILE_PATH)
log.Printf("3 %v",CONFIG)
if err!=nil{
logger.Fatal("Failed to load config ",err)
}
log.Printf(CONFIG.FileStoreName)
logger.SetPrefix(time.Now().Format("2023-08-02 15:04:05") + " [main.go] ")
logger.Println(CONFIG.FileStoreName)
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 {
logger.Panicf("Logging err: %s\n", err.Error())
log.Panicf("Logging err: %s\n", err.Error()) // panic if there is an error
}
//log.Printf("listening at port 8080...")
logger.Println("service listening at port 8080...")
log.Fatal(http.ListenAndServe(":8080", router)) // Note, the port is usually gotten from the environment.
}