← history for repobrowser/main.go
65b78ac4repobrowser/main.go60 lines⬡ raw↓ download
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main

import (
    "errors"
    "fmt"
    "log"
    "os"
    "repobrowser/internal/config"
    "repobrowser/internal/handlers"

    "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()

    r.GET("/", handlers.HandleRepoList(cfg))

    repo := r.Group("/:repo")
    {
        repo.GET("/", handlers.HandleIndex(cfg))
        repo.GET("/refs", handlers.HandleRefs(cfg))
        repo.GET("/log", handlers.HandleLog(cfg))
        repo.GET("/commit", handlers.HandleCommit(cfg))
        repo.GET("/history", handlers.HandleHistory(cfg))
        repo.GET("/view", handlers.HandleView(cfg))
        repo.GET("/raw", handlers.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)
        }
    }
}