From 2dd4cf35aab8324608a83d337459fd8354521b92 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Mon, 27 May 2024 22:36:50 +0200 Subject: feat: Wraps handler into its own package Although this creates more complex folder structure will allow in the feature for a easier testing of those given handlers. --- main.go | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) (limited to 'main.go') 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) -- cgit v1.2.3