Skip to content

Commit c650e0c

Browse files
author
Julien Vallée
committed
Accept Listen Address as an ENV VAR as well
1 parent eac7521 commit c650e0c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,25 @@ type discordEmbedField struct {
6767
Value string `json:"value"`
6868
}
6969

70+
const defaultListenAddress = "127.0.0.1:9094"
71+
7072
func main() {
7173
envWhURL := os.Getenv("DISCORD_WEBHOOK")
7274
whURL := flag.String("webhook.url", envWhURL, "Discord WebHook URL.")
73-
listenAddress := flag.String("listen.address", "127.0.0.1:9094", "Address:Port to listen on.")
75+
76+
envListenAddress := os.Getenv("LISTEN_ADDRESS")
77+
listenAddress := flag.String("listen.address", envListenAddress, "Address:Port to listen on.")
78+
7479
flag.Parse()
7580

7681
if *whURL == "" {
7782
log.Fatalf("Environment variable 'DISCORD_WEBHOOK' or CLI parameter 'webhook.url' not found.")
7883
}
7984

85+
if *listenAddress == "" {
86+
*listenAddress = defaultListenAddress
87+
}
88+
8089
re := regexp.MustCompile(`https://discord(?:app)?.com/api/webhooks/[0-9]{18}/[a-zA-Z0-9_-]+`)
8190
if ok := re.Match([]byte(*whURL)); !ok {
8291
log.Fatalf("The Discord WebHook URL doesn't seem to be valid.")

0 commit comments

Comments
 (0)