Allow to pass port using an environment variable (#44)
This commit is contained in:
committed by
GitHub
parent
09cbe40f67
commit
04e535038e
@ -22,7 +22,7 @@ Tiny Go webserver that prints os information and HTTP request to output
|
|||||||
|
|
||||||
- `cert`: give me a certificate.
|
- `cert`: give me a certificate.
|
||||||
- `key`: give me a key.
|
- `key`: give me a key.
|
||||||
- `port`: give me a port number. (default: 80)
|
- `port`: give me a port number. (it can be also defined with `WHOAMI_PORT` environment variable) (default: 80)
|
||||||
- `name`: give me a name. (it can be also defined with `WHOAMI_NAME` environment variable)
|
- `name`: give me a name. (it can be also defined with `WHOAMI_NAME` environment variable)
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
10
app.go
10
app.go
@ -43,7 +43,7 @@ func init() {
|
|||||||
flag.StringVar(&cert, "cert", "", "give me a certificate")
|
flag.StringVar(&cert, "cert", "", "give me a certificate")
|
||||||
flag.StringVar(&key, "key", "", "give me a key")
|
flag.StringVar(&key, "key", "", "give me a key")
|
||||||
flag.StringVar(&ca, "cacert", "", "give me a CA chain, enforces mutual TLS")
|
flag.StringVar(&ca, "cacert", "", "give me a CA chain, enforces mutual TLS")
|
||||||
flag.StringVar(&port, "port", "80", "give me a port number")
|
flag.StringVar(&port, "port", getEnv("WHOAMI_PORT", "80"), "give me a port number")
|
||||||
flag.StringVar(&name, "name", os.Getenv("WHOAMI_NAME"), "give me a name")
|
flag.StringVar(&name, "name", os.Getenv("WHOAMI_NAME"), "give me a name")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,3 +306,11 @@ func fillContent(length int64) io.ReadSeeker {
|
|||||||
|
|
||||||
return bytes.NewReader(b)
|
return bytes.NewReader(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEnv(key, fallback string) string {
|
||||||
|
value := os.Getenv(key)
|
||||||
|
if len(value) == 0 {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user