cerrado @ e52226c05fb54dfe41c9bc5ebc6ce1b7ded7e1fe

 1package handler
 2
 3import (
 4	"net/http"
 5
 6	serverconfig "git.gabrielgio.me/cerrado/pkg/config"
 7	"git.gabrielgio.me/cerrado/pkg/handler/about"
 8	"git.gabrielgio.me/cerrado/pkg/handler/config"
 9	"git.gabrielgio.me/cerrado/pkg/handler/git"
10	"git.gabrielgio.me/cerrado/pkg/handler/static"
11	"git.gabrielgio.me/cerrado/pkg/service"
12)
13
14// Mount handler gets the requires service and repository to build the handlers
15// This functons wraps the whole handler package and wraps it into one part so
16// its sub package don't leak in other places.
17func MountHandler(
18	gitService *service.GitService,
19	configRepo *serverconfig.ConfigurationRepository,
20) (http.Handler, error) {
21	var (
22		gitHandler   = git.NewGitHandler(gitService)
23		aboutHandler = about.NewAboutHandler(configRepo)
24		configHander = config.ConfigFile(configRepo)
25	)
26
27	staticHandler, err := static.NewStaticHander("/static/")
28	if err != nil {
29		return nil, err
30	}
31
32	mux := http.NewServeMux()
33	mux.Handle("/static/", staticHandler)
34	mux.HandleFunc("/config", configHander)
35	mux.HandleFunc("/about", aboutHandler.About)
36	mux.HandleFunc("/{name}", gitHandler.Item)
37	mux.HandleFunc("/", gitHandler.List)
38	return mux, nil
39}