Skip to content

Commit ea94a7c

Browse files
committed
panic on config validation error
#75
1 parent ddfab07 commit ea94a7c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Settings:
3939

4040
Environment variable|default|description
4141
--------------------|-------|------------
42-
RABBIT_URL | <http://localhost:15672>| url to rabbitMQ management plugin
42+
RABBIT_URL | <http://localhost:15672>| url to rabbitMQ management plugin (must start with http(s)://)
4343
RABBIT_USER | guest | username for rabbitMQ management plugin
4444
RABBIT_PASSWORD | guest | password for rabbitMQ management plugin
4545
RABBIT_USER_FILE| | location of file with username (useful for docker secrets)

config.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"io/ioutil"
56
"os"
67
"regexp"
@@ -59,6 +60,8 @@ func initConfig() {
5960
if url := os.Getenv("RABBIT_URL"); url != "" {
6061
if valid, _ := regexp.MatchString("https?://[a-zA-Z.0-9]+", strings.ToLower(url)); valid {
6162
config.RabbitURL = url
63+
} else {
64+
panic(fmt.Errorf("Rabbit URL must start with http:// or https://"))
6265
}
6366
}
6467

@@ -95,6 +98,8 @@ func initConfig() {
9598
if port := os.Getenv("PUBLISH_PORT"); port != "" {
9699
if _, err := strconv.Atoi(port); err == nil {
97100
config.PublishPort = port
101+
} else {
102+
panic(fmt.Errorf("The configured port is not a valid number: %v", port))
98103
}
99104

100105
}

0 commit comments

Comments
 (0)