-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.go
48 lines (38 loc) · 1.09 KB
/
backend.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
package main
import (
"net/http"
"time"
"github.com/ksaritek/opentracing-sample/cmd"
"github.com/ksaritek/opentracing-sample/pkg/db"
"github.com/ksaritek/opentracing-sample/pkg/route"
"github.com/ksaritek/opentracing-sample/pkg/tracing"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
func init() {
viper.SetDefault("address", ":8080")
}
func main() {
cmd := cmd.NewRoot()
if err := cmd.Execute(); err != nil {
panic(errors.Wrap(err, "could not execute command:"))
}
log.Infof("config_file: %s", viper.ConfigFileUsed())
_, closer, err := tracing.Init("opentracing-sample")
if err != nil {
panic(errors.Wrap(err, "could not start opentracing:"))
}
defer closer.Close()
log.Info("opentracing is configured")
router := route.NewRoutes(db.NewRepository())
srv := &http.Server{
Addr: ":9090",
Handler: tracing.HTTPMiddleware(router, "backend"),
// Good practice: enforce timeouts for servers you create!
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
log.Info("HTTP server is started")
log.Fatal(srv.ListenAndServe())
}