-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (46 loc) · 1.42 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
package main
import (
"fmt"
"os"
"time"
"github.com/mehmetumit/dexus/helper"
"github.com/mehmetumit/dexus/internal/adapters/fileredirect"
"github.com/mehmetumit/dexus/internal/adapters/memcache"
"github.com/mehmetumit/dexus/internal/adapters/rest"
"github.com/mehmetumit/dexus/internal/adapters/stdlog"
"github.com/mehmetumit/dexus/internal/core/app"
)
var (
Version string
Commit string
)
// Composition root
func main() {
// Load with these defaults if envs are not set
envCfg := helper.LoadConfigWithDefaults(helper.Config{
DebugLevel: true,
Host: "",
Port: "8080",
ReadTimeoutMS: 1000 * time.Millisecond,
WriteTimeoutMS: 1000 * time.Millisecond,
CacheTTLSec: 60 * time.Second,
YamlRedirectPath: "configs/redirection.yaml",
})
logger := stdlog.NewStdLog(envCfg.DebugLevel)
logger.Info(fmt.Sprintf("Version: %s | Commit: %s", Version, Commit))
cacher := memcache.NewMemCache(logger)
redirectRepo, err := fileredirect.NewYamlRedirect(logger, envCfg.YamlRedirectPath)
if err != nil {
os.Exit(1)
}
appCore := app.NewApp(app.AppConfig{
Logger: logger,
RedirectionRepo: redirectRepo,
})
rest.NewServer(logger, &rest.ServerConfig{
Addr: envCfg.Host + ":" + envCfg.Port,
//IdleTimeout: 90 * time.Second,
ReadTimeout: envCfg.ReadTimeoutMS,
WriteTimeout: envCfg.WriteTimeoutMS,
}, appCore, rest.WithCacher(cacher, logger, envCfg.CacheTTLSec))
}