-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (45 loc) · 961 Bytes
/
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
package main
import (
"context"
"errors"
"fmt"
"github.com/joho/godotenv"
"log"
"os"
"os/signal"
"syscall"
"github.com/teamscanworks/codebreaker/server"
)
const (
defaultUpdateFreq = "@daily"
)
func main() {
listenAddr, err := parseArgs()
if err != nil {
log.Fatal(err)
}
err = godotenv.Load()
if err != nil {
fmt.Print("Error loading .env file")
}
registryUrl := os.Getenv("REGISTRY_URL")
if registryUrl == "" {
log.Fatal(errors.New("Error loading REGISTRY_URL env variable \n"))
}
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancel()
err = server.Serve(ctx, registryUrl, listenAddr, defaultUpdateFreq)
if err != nil {
fmt.Print(err)
}
}
func parseArgs() (string, error) {
switch len(os.Args) {
case 2:
return os.Args[1], nil
case 1:
return ":8080", nil
default:
return "", errors.New("expected 0 or 1 argument. \n\nUsage: codebreaker [listen-addr]")
}
}