← history for altgit.go
fe12c3fbaltgit.go52 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
package main

import (
	"fmt"
	"log"
	"net/http"
	"os"

	githttp "github.com/AaronO/go-git-http"
)

func main() {
	var instanceName string
	args := os.Args
	if len(args) < 2 {
		instanceName = "default"
		fmt.Println("Loading default config")
	} else {
		instanceName = args[1]
		fmt.Printf("Loading instance: [%s] config", instanceName)
	}

	cfg, err := LoadConfig(os.Getenv("HOME") + "/.config/altgit/" + instanceName + ".cfg")
	if err != nil {
		log.Fatal("Could not load config file", err)
	}

	fmt.Printf("Start Server with RepoRoot: [%s]\n", cfg.RepoRoot)

	/*
	   GitAuthenticator := auth.Authenticator(func(info auth.AuthInfo) (bool, error) {
	       return AuthorizeAllGitRequests(info)
	   })
	*/

	git := githttp.New(cfg.RepoRoot)
	//http.Handle("/", GitAuthenticator(git))
	http.Handle("/", git)
	//http.Handle("/api", http.HandlerFunc(createRepo(git)))

	if cfg.ServerTLSCertificate == "" || cfg.ServerTLSKey == "" {
		err := http.ListenAndServe(cfg.Endpoint, nil)
		if err != nil {
			log.Fatal("Could not start server", err)
		}
	} else {
		err := http.ListenAndServeTLS(cfg.Endpoint, cfg.ServerTLSCertificate, cfg.ServerTLSKey, nil)
		if err != nil {
			log.Fatal("Could not start TLS server", err)
		}
	}
}