-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.go
58 lines (50 loc) · 1.32 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
package main
import (
"fmt"
"net/http"
"slo-tracker/api"
v1 "slo-tracker/api/v1"
"slo-tracker/config"
appmiddleware "slo-tracker/middleware"
"slo-tracker/pkg/trace"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/rs/cors"
)
var (
name = "slo-tracker"
version = "0.0.1"
)
func main() {
config.Initialize()
api.InitService(name, version)
trace.Setup(config.Env)
router := chi.NewRouter()
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE"},
AllowedHeaders: []string{
"Origin", "Authorization", "Access-Control-Allow-Origin",
"Access-Control-Allow-Header", "Accept",
"Content-Type", "X-CSRF-Token",
},
ExposedHeaders: []string{
"Content-Length", "Access-Control-Allow-Origin", "Origin",
},
AllowCredentials: true,
MaxAge: 300,
})
// cross & loger middleware
router.Use(cors.Handler)
router.Use(
middleware.Logger,
appmiddleware.Recoverer,
)
// Initialize the version 1 routes of the API
// router.Get("/", api.IndexHandeler)
// router.Get("/top", api.HealthHandeler)
// router.Route("/v1", v1.Init)
router.Route("/", v1.Routes)
trace.Log.Infof("Starting %s:%s on port :%s\n", name, version, config.Port)
http.ListenAndServe(fmt.Sprintf(":%s", config.Port), router)
}