package handler import ( "net/http" serverconfig "git.gabrielgio.me/cerrado/pkg/config" "git.gabrielgio.me/cerrado/pkg/ext" "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.ServeStaticHandler() if err != nil { return nil, err } mux := http.NewServeMux() mux.HandleFunc("/static/{file}", m(staticHandler)) mux.HandleFunc("/{name}/about/{$}", m(gitHandler.About)) mux.HandleFunc("/{name}", m(gitHandler.Summary)) mux.HandleFunc("/{name}/refs/{$}", m(gitHandler.Refs)) mux.HandleFunc("/{name}/tree/{ref}/{rest...}", m(gitHandler.Tree)) mux.HandleFunc("/{name}/blob/{ref}/{rest...}", m(gitHandler.Blob)) mux.HandleFunc("/{name}/log/{ref}", m(gitHandler.Log)) mux.HandleFunc("/config", m(configHander)) mux.HandleFunc("/about", m(aboutHandler.About)) mux.HandleFunc("/", m(gitHandler.List)) return mux, nil } func m(next func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) { return ext.Compress(next) }