/
main.go
56 lines (48 loc) · 1.08 KB
/
main.go
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
package main
import (
"flag"
"http"
"http/cgi"
"log"
"os"
"strconv"
)
var (
cgitPath = flag.String("cgit", "/var/www/htdocs/cgit/cgit",
"Location of cgit executable.")
cgitRes = flag.String("cgitres", "/var/www/htdocs/cgit",
"Location of cgit resources.")
config = flag.String("config", "",
"Location of the cgit configuration file.")
port = flag.Int("port", 5000,
"TCP port to listen on.")
addr = flag.String("addr", "127.0.0.1",
"Address to listen on.")
)
func main() {
log.SetFlags(0)
flag.Parse()
cgiHandler := &cgi.Handler{
Path: *cgitPath,
Env: []string{},
InheritEnv: []string{
"CGIT_CONFIG",
},
}
if *config != "" {
cgiHandler.Env = append(cgiHandler.Env,
"CGIT_CONFIG="+*config)
}
fs := http.FileServer(http.Dir(*cgitRes))
http.Handle("/cgit.css", fs)
http.Handle("/cgit.png", fs)
http.Handle("/", cgiHandler)
err := http.ListenAndServe(*addr + ":" + strconv.Itoa(*port), nil)
if err != nil {
log.Fatal(err)
}
// Everything seems to work: daemonize (close file handles)
os.Stdin.Close()
os.Stdout.Close()
os.Stderr.Close()
}