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 /pkg/handler/router.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 'pkg/handler/router.go')
-rw-r--r-- | pkg/handler/router.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/pkg/handler/router.go b/pkg/handler/router.go new file mode 100644 index 0000000..a8c9c6f --- /dev/null +++ b/pkg/handler/router.go @@ -0,0 +1,38 @@ +package handler + +import ( + "net/http" + + serverconfig "git.gabrielgio.me/cerrado/pkg/config" + "git.gabrielgio.me/cerrado/pkg/handler/about" + "git.gabrielgio.me/cerrado/pkg/handler/config" + "git.gabrielgio.me/cerrado/pkg/handler/git" + "git.gabrielgio.me/cerrado/pkg/handler/static" + "git.gabrielgio.me/cerrado/pkg/service" +) + +// Mount handler gets the requires service and repository to build the handlers +// This functons wraps the whole handler package and wraps it into one part so +// its sub package don't leak in other places. +func MountHandler( + gitService *service.GitService, + configRepo *serverconfig.ConfigurationRepository, +) (http.Handler, error) { + var ( + gitHandler = git.NewGitHandler(gitService) + aboutHandler = about.NewAboutHandler(configRepo) + configHander = config.ConfigFile(configRepo) + ) + + staticHandler, err := static.NewStaticHander("/static/") + if err != nil { + return nil, err + } + + mux := http.NewServeMux() + mux.Handle("/static/", staticHandler) + mux.HandleFunc("/config", configHander) + mux.HandleFunc("/about", aboutHandler.About) + mux.HandleFunc("/", gitHandler.List) + return mux, nil +} |