aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go30
1 files changed, 6 insertions, 24 deletions
diff --git a/main.go b/main.go
index 76da07b..eedff5e 100644
--- a/main.go
+++ b/main.go
@@ -10,7 +10,6 @@ import (
"time"
"git.gabrielgio.me/cerrado/pkg/config"
- "git.gabrielgio.me/cerrado/pkg/git"
"git.gabrielgio.me/cerrado/pkg/handler"
"git.gabrielgio.me/cerrado/pkg/service"
"git.gabrielgio.me/cerrado/pkg/worker"
@@ -33,38 +32,21 @@ func run(ctx context.Context) error {
flag.Parse()
- mux := http.NewServeMux()
-
- staticHandler, err := handler.NewStaticHander("/static/")
+ // repositorie
+ configRepo, err := config.LoadConfigurationRepository(*configPath)
if err != nil {
return err
}
- f, err := os.Open(*configPath)
- if err != nil {
- return err
- }
+ // services
+ gitService := service.NewGitService(configRepo)
- config, err := config.Parse(f)
+ handler, err := handler.MountHandler(gitService, configRepo)
if err != nil {
return err
}
- // repositories
- gitServer := git.NewGitServerRepository(config.Scan.Path)
-
- // services
- gitService := service.NewGitService(gitServer)
-
- //handlers
- gitHandler := handler.NewGitHandler(gitService)
- aboutHandler := handler.NewAboutHandler(config.RootReadme)
-
- mux.Handle("/static/", staticHandler)
- mux.HandleFunc("/config", handler.ConfigFile(*configPath))
- mux.HandleFunc("/about", aboutHandler.About)
- mux.HandleFunc("/", gitHandler.List)
- serverTask := worker.NewServerTask(&http.Server{Handler: mux, Addr: "0.0.0.0:8080"})
+ serverTask := worker.NewServerTask(&http.Server{Handler: handler, Addr: "0.0.0.0:8080"})
pool := worker.NewTaskPool()
pool.AddTask("http-server", 5*time.Second, serverTask)