-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move from zap to logrus, add graceful shutdown, change config parsing
- Loading branch information
Showing
11 changed files
with
164 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
) | ||
|
||
type Config struct { | ||
WebhookUrl string | ||
BotToken string | ||
DbPath string | ||
ListenAddress string | ||
} | ||
|
||
func parseConfig() (*Config, error) { | ||
webhookUrl := os.Getenv("WEBHOOK_URL") | ||
if webhookUrl == "" { | ||
return nil, errors.New("WEBHOOK_URL environment variable is not set.") | ||
} | ||
|
||
botToken := os.Getenv("BOT_TOKEN") | ||
if botToken == "" { | ||
return nil, errors.New("BOT_TOKEN environment variable is not set.") | ||
} | ||
|
||
dbPath := os.Getenv("DB_PATH") | ||
if botToken == "" { | ||
dbPath = "./db.sqlite3" | ||
} | ||
|
||
listenAddress := os.Getenv("LISTEN_ADDRESS") | ||
if botToken == "" { | ||
listenAddress = ":8080" | ||
} | ||
|
||
return &Config{ | ||
WebhookUrl: webhookUrl, | ||
BotToken: botToken, | ||
DbPath: dbPath, | ||
ListenAddress: listenAddress, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.