| 29 | } |
| 30 | |
| 31 | func (c *config) parse() { |
| 32 | flag.BoolVar(&c.debug, "debug", false, "Enable debug logging") |
| 33 | flag.StringVar(&c.certFile, "tls-cert-file", os.Getenv("CERT_FILE"), "File containing the certificate for HTTPS") |
| 34 | flag.StringVar(&c.keyFile, "tls-key-file", os.Getenv("KEY_FILE"), "File containing the private key for HTTPS") |
| 35 | flag.StringVar(&c.address, "address", defaultHTTPSAddress, "The address to listen on") |
| 36 | flag.Parse() |
| 37 | |
| 38 | if (c.certFile != "" || c.keyFile != "") && !(c.certFile != "" && c.keyFile != "") { |
| 39 | log.Fatal("Config parse error: both of TLS cert & key must be provided or neither (for testing )") |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | // support non-HTTPS for local testing |
| 44 | if (c.certFile == "" && c.keyFile == "") && c.address == defaultHTTPSAddress { |
| 45 | c.address = defaultHTTPAddress |
| 46 | } |
| 47 | |
| 48 | if c.debug { |
| 49 | log.SetLevel(log.DebugLevel) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | func main() { |
| 54 | var cfg = &config{} |