diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-05-27 22:36:50 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-05-27 22:42:16 +0200 |
commit | 2dd4cf35aab8324608a83d337459fd8354521b92 (patch) | |
tree | b65ecc803260bc268332fb2fbce83ab5dd209dbc /main.go | |
parent | 60e8e751c76d949a28eefe0c5462e0cf17337217 (diff) | |
download | cerrado-2dd4cf35aab8324608a83d337459fd8354521b92.tar.gz cerrado-2dd4cf35aab8324608a83d337459fd8354521b92.tar.bz2 cerrado-2dd4cf35aab8324608a83d337459fd8354521b92.zip |
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.
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 30 |
1 files changed, 6 insertions, 24 deletions
@@ -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) |