-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
65 lines (56 loc) · 1.45 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
package gcp
import (
"fmt"
"os"
)
type PubSubConfig struct {
credentials string
projectID string
dataTopicID string
subscription string
}
// NewPubSubConfig creates a new PubSubConfig from the environment variables
func NewPubSubConfig() (PubSubConfig, error) {
var errMsg string
credentials := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
if credentials == "" {
errMsg += "GOOGLE_APPLICATION_CREDENTIALS\n"
}
projectID := os.Getenv("GOOGLE_PROJECT_ID")
if projectID == "" {
errMsg += "GOOGLE_PROJECT_ID\n"
}
dataTopicID := os.Getenv("DATA_TOPIC_ID")
if dataTopicID == "" {
errMsg += "DATA_TOPIC_ID\n"
}
subscription := os.Getenv("DATA_TOPIC_SUBSCRIPTION")
if subscription == "" {
errMsg += "DATA_TOPIC_SUBSCRIPTION\n"
}
if errMsg != "" {
return PubSubConfig{}, fmt.Errorf("Please set the following Environment Variables:\n%s", errMsg)
}
return PubSubConfig{
credentials: credentials,
projectID: projectID,
dataTopicID: dataTopicID,
subscription: subscription,
}, nil
}
// Credentials returns the GCP credential file location
func (c PubSubConfig) Credentials() string {
return c.credentials
}
// ProjectID returns the GCP Project ID
func (c PubSubConfig) ProjectID() string {
return c.projectID
}
// DataTopicID returns the GCP pubsub topic
func (c PubSubConfig) DataTopicID() string {
return c.dataTopicID
}
// DataTopicID returns the GCP pubsub topic
func (c PubSubConfig) Subscription() string {
return c.subscription
}