/** * AltGit - altgit * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Paolo Lulli * @copyright Paolo Lulli 2026 */ package main import ( "errors" "fmt" "log" "os" "repobrowser/internal/config" "repobrowser/internal/routes" "strings" githttp "github.com/AaronO/go-git-http" "github.com/gin-gonic/gin" ) func main() { configPath := os.Getenv("HOME") + "/.config/repobrowser.json" if _, err := os.Stat(configPath); errors.Is(err, os.ErrNotExist) { fmt.Printf("Config file %s doesn't exist\n", configPath) os.Exit(1) } cfg := config.GetClientConfig(configPath) //var c = RepositoryBrowserApp{Config: cfg} r := gin.Default() err := r.SetTrustedProxies([]string{"127.0.0.1"}) if err != nil { return } // templates and static must exist on the target filesystem r.LoadHTMLGlob("templates/*") r.Static("/static", "./static") //---- //--------------------------------- gitHandler := githttp.New(cfg.Root) r.Any("/git/*repoPath", func(c *gin.Context) { // Strip the /git prefix so go-git-http sees /myrepo.git/... c.Request.URL.Path = strings.TrimPrefix(c.Request.URL.Path, "/git") c.Request.RequestURI = strings.TrimPrefix(c.Request.RequestURI, "/git") gitHandler.ServeHTTP(c.Writer, c.Request) }) //--------------------------------- r.GET("/", routes.HandleRepoList(cfg)) repo := r.Group("/:repo") { repo.GET("/", routes.HandleIndex(cfg)) repo.GET("/refs", routes.HandleRefs(cfg)) repo.GET("/log", routes.HandleLog(cfg)) repo.GET("/commit", routes.HandleCommit(cfg)) repo.GET("/history", routes.HandleHistory(cfg)) repo.GET("/view", routes.HandleView(cfg)) repo.GET("/raw", routes.HandleRaw(cfg)) } var iface string if "" == cfg.Interface { iface = "0.0.0.0:8080" } else { iface = cfg.Interface } fmt.Printf("Starting altgit on: -> http://%s\n", iface) if cfg.TlsCertificate == "" || cfg.TlsKeyFile == "" { err := r.Run(iface) if err != nil { log.Fatal("Could not start server", err) } } else { err := r.RunTLS(cfg.Interface, cfg.TlsCertificate, cfg.TlsKeyFile) if err != nil { log.Fatal("Could not start TLS server", err) } } }