-
Notifications
You must be signed in to change notification settings - Fork 54
/
main.go
51 lines (47 loc) · 1.21 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
package main
import (
"fmt"
"log"
"net"
"net/http"
"os"
"time"
"github.com/jpillora/installer/handler"
"github.com/jpillora/opts"
"github.com/jpillora/requestlog"
)
var version = "0.0.0-src"
func main() {
c := handler.DefaultConfig
opts.New(&c).Repo("github.com/jpillora/installer").Version(version).Parse()
log.Printf("default user is '%s'", c.User)
if c.Token == "" && os.Getenv("GH_TOKEN") != "" {
c.Token = os.Getenv("GH_TOKEN") // GH_TOKEN was renamed
}
if c.Token != "" {
log.Printf("github token will be used for requests to api.github.com")
}
if c.ForceUser != "" {
log.Printf("locked user to '%s'", c.ForceUser)
}
if c.ForceRepo != "" {
log.Printf("locked repo to '%s'", c.ForceRepo)
}
addr := fmt.Sprintf("%s:%d", c.Host, c.Port)
l, err := net.Listen("tcp4", addr)
if err != nil {
log.Fatal(err)
}
log.Printf("listening on %s...", addr)
h := &handler.Handler{Config: c}
lh := requestlog.WrapWith(h, requestlog.Options{
TrustProxy: true, // assume will be run in paas
Filter: func(r *http.Request, code int, duration time.Duration, size int64) bool {
return r.URL.Path != "/healthz"
},
})
if err := http.Serve(l, lh); err != nil {
log.Fatal(err)
}
log.Print("exiting")
}