|
@@ -21,6 +21,7 @@ var (
|
21
|
21
|
ctx context.Context
|
22
|
22
|
client *github.Client
|
23
|
23
|
release *github.RepositoryRelease
|
|
24
|
+ ticker *time.Ticker
|
24
|
25
|
)
|
25
|
26
|
|
26
|
27
|
func fetchLatest() {
|
|
@@ -29,6 +30,7 @@ func fetchLatest() {
|
29
|
30
|
log.Println("Error retrieving latest release", err)
|
30
|
31
|
return
|
31
|
32
|
}
|
|
33
|
+ log.Printf("Found latest release: %s\n", *latest.Name)
|
32
|
34
|
release = latest
|
33
|
35
|
}
|
34
|
36
|
|
|
@@ -73,10 +75,26 @@ func parseRepo(fullRepo *string) error {
|
73
|
75
|
return nil
|
74
|
76
|
}
|
75
|
77
|
|
|
78
|
+func initTicker(seconds int) {
|
|
79
|
+ if seconds > 0 {
|
|
80
|
+ log.Printf("Starting ticker for polling once every %d seconds.\n", seconds)
|
|
81
|
+ ticker = time.NewTicker(time.Duration(seconds) * time.Second)
|
|
82
|
+ go func() {
|
|
83
|
+ for range ticker.C {
|
|
84
|
+ fetchLatest()
|
|
85
|
+ }
|
|
86
|
+ }()
|
|
87
|
+ } else {
|
|
88
|
+ log.Println("Not starting ticker; performing one off fetch and relying on webhooks.")
|
|
89
|
+ }
|
|
90
|
+ fetchLatest()
|
|
91
|
+}
|
|
92
|
+
|
76
|
93
|
func main() {
|
77
|
94
|
redirect = flag.String("redirect", "", "if specified, requests for / will be redirected to this url")
|
78
|
95
|
var fullRepo = flag.String("repo", "", "the repository to redirect releases for, in user/repo format [required]")
|
79
|
96
|
var port = flag.Int("port", 8080, "the port to listen on for HTTP requests")
|
|
97
|
+ var poll = flag.Int("poll", 3600, "the amount of time to wait between polling for releases; 0 to disable polling")
|
80
|
98
|
|
81
|
99
|
flag.Parse()
|
82
|
100
|
|
|
@@ -88,15 +106,6 @@ func main() {
|
88
|
106
|
|
89
|
107
|
client = github.NewClient(nil)
|
90
|
108
|
|
91
|
|
- ticker := time.NewTicker(time.Hour)
|
92
|
|
- go func() {
|
93
|
|
- fetchLatest()
|
94
|
|
- for range ticker.C {
|
95
|
|
- fetchLatest()
|
96
|
|
- }
|
97
|
|
- }()
|
98
|
|
-
|
99
|
|
-
|
100
|
109
|
var cancel context.CancelFunc
|
101
|
110
|
ctx, cancel = context.WithCancel(context.Background())
|
102
|
111
|
|
|
@@ -107,13 +116,17 @@ func main() {
|
107
|
116
|
go func() {
|
108
|
117
|
for sig := range c {
|
109
|
118
|
cancel()
|
110
|
|
- ticker.Stop()
|
111
|
|
- log.Printf("Received %s, exiting.", sig.String())
|
|
119
|
+ if ticker != nil {
|
|
120
|
+ ticker.Stop()
|
|
121
|
+ }
|
|
122
|
+ log.Printf("Received %s, exiting.\n", sig.String())
|
112
|
123
|
os.Exit(0)
|
113
|
124
|
}
|
114
|
125
|
}()
|
115
|
126
|
|
116
|
|
- log.Printf("Listing on :%d", *port)
|
|
127
|
+ initTicker(*poll)
|
|
128
|
+
|
|
129
|
+ log.Printf("Listing on :%d\n", *port)
|
117
|
130
|
|
118
|
131
|
server := &http.Server{
|
119
|
132
|
Addr: fmt.Sprintf(":%d", *port),
|