-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
56 lines (44 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
52
53
54
55
56
package main
import (
"flag"
"log"
"net/http"
"os"
"github.com/utilitywarehouse/registry-browser/registry"
"github.com/utilitywarehouse/registry-browser/s3"
)
var (
flagS3Bucket = flag.String("s3-bucket", defaultFromEnv("REGISTRY_BROWSER_S3_BUCKET", ""), "S3 bucket name")
flagListenAddress = flag.String("listen-address", defaultFromEnv("REGISTRY_BROWSER_LISTEN_ADDRESS", ":8080"), "Listen address")
flagRegistryURL = flag.String("registry-url", defaultFromEnv("REGISTRY_BROWSER_REGISTRY_URL", "http://localhost:5000"), "Registry url")
)
func defaultFromEnv(key, defaultValue string) string {
v := os.Getenv(key)
if len(v) == 0 {
return defaultValue
}
return v
}
func main() {
flag.Parse()
if *flagS3Bucket == "" {
log.Fatalln("Must provide an s3 bucket")
}
if *flagRegistryURL == "" {
log.Fatalln("Must provide a registry URL")
}
registryClient, err := registry.New(*flagRegistryURL)
if err != nil {
log.Fatalln(err)
}
s3Client, err := s3.New(*flagS3Bucket)
if err != nil {
log.Fatalln(err)
}
s, err := newServer(registryClient, s3Client)
if err != nil {
log.Fatalln(err)
}
log.Printf("Listening on %s", *flagListenAddress)
log.Fatalln(http.ListenAndServe(*flagListenAddress, s))
}