cerrado @ 18aa098f50e2a2c7db01dd4d04dde460fd40f5d5

 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.ServeStaticHandler()
28	if err != nil {
29		return nil, err
30	}
31
32	mux := http.NewServeMux()
33
34	mux.HandleFunc("/static/{file}", staticHandler)
35	mux.HandleFunc("/{name}/about/{$}", gitHandler.About)
36	mux.HandleFunc("/{name}", gitHandler.Summary)
37	mux.HandleFunc("/{name}/refs/{$}", gitHandler.Refs)
38	mux.HandleFunc("/{name}/tree/{ref}/{rest...}", gitHandler.Tree)
39	mux.HandleFunc("/{name}/blob/{ref}/{rest...}", gitHandler.Blob)
40	mux.HandleFunc("/{name}/log/{ref}", gitHandler.Log)
41	mux.HandleFunc("/config", configHander)
42	mux.HandleFunc("/about", aboutHandler.About)
43	mux.HandleFunc("/", gitHandler.List)
44	return mux, nil
45}