-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (50 loc) · 1.16 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 (
"errors"
"flag"
"fmt"
"log"
"time"
)
// Command-line flags
var (
repoOwner, repoName string
port int
updateSecs int
)
func init() {
flag.StringVar(&repoOwner, "repo-owner", "", "The name of the Git repository owner")
flag.StringVar(&repoName, "repo-name", "", "The name of the Git repository")
flag.IntVar(&port, "port", 8080, "The port to listen on")
flag.IntVar(&updateSecs, "t", 0, "The number of seconds to wait between config updates")
}
func checkFlags() error {
if repoOwner == "" {
return errors.New("-repo-owner is required")
}
if repoName == "" {
return errors.New("-repo-name is required")
}
if port <= 0 {
return fmt.Errorf("invalid port number: %d", port)
}
if updateSecs <= 0 {
return errors.New("-t must a positive integer")
}
return nil
}
func execute() error {
address := fmt.Sprintf(":%d", port)
log.Printf("listening at %s", address)
s := NewServer(repoOwner, repoName, time.Duration(updateSecs)*time.Second)
return s.ListenAndServe(address)
}
func main() {
flag.Parse()
if err := checkFlags(); err != nil {
log.Fatal(err)
}
if err := execute(); err != nil {
log.Fatal(err)
}
}