-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
72 lines (61 loc) · 1.62 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
)
// LoadEnvFromConfig loads environment variables from a .env file
func LoadEnvFromConfig() error {
err := godotenv.Load(".env")
if err != nil {
return fmt.Errorf("failed to load .env file: %w", err)
}
return nil
}
// scrapeConfig is a configuration for scraping Yahoo! Realtime Search
type scrapeConfig struct {
keyword string
authorId string
}
// getScrapeConfig gets a scrape configuration from environment variables
func getScrapeConfig() scrapeConfig {
return scrapeConfig{
keyword: os.Getenv("SEARCH_KEYWORD"),
authorId: os.Getenv("SEARCH_AUTHOR_ID"),
}
}
// WebhookConfig is a configuration for a Discord webhook
type webhookConfig struct {
URL string
Username *string
AvatarURL string
}
// getWebhookConfig gets a webhook configuration from environment variables
func getWebhookConfig() webhookConfig {
userName := os.Getenv("WEBHOOK_USERNAME")
var userNamePointer *string
if userName != "" {
userNamePointer = &userName
}
return webhookConfig{
URL: os.Getenv("WEBHOOK_URL"),
Username: userNamePointer,
AvatarURL: os.Getenv("WEBHOOK_AVATAR_URL"),
}
}
// dynamoDBConfig is a configuration for DynamoDB
type dynamoDBConfig struct {
TableName string
Region *string
EndpointURL *string
}
// getDynamoDBConfig gets a DynamoDB configuration from environment variables
func getDynamoDBConfig() dynamoDBConfig {
region := os.Getenv("AWS_REGION")
endpointURL := os.Getenv("DYNAMODB_ENDPOINT_URL")
return dynamoDBConfig{
TableName: os.Getenv("HISTORY_TABLE"),
Region: ®ion,
EndpointURL: &endpointURL,
}
}