-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (41 loc) · 1.04 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
package matomo
import (
"fmt"
"log"
"os"
"strings"
)
type Configuration struct {
Domain string
AuthToken string
SiteID string // if not provided, will be required in the call
Rec string // currently must always be set to 1
}
var config *Configuration
func Setup() {
if config != nil {
return
}
config = &Configuration{}
config.Domain = strings.TrimSuffix(envHelper("MATOMO_DOMAIN", ""), "/")
if config.Domain == "" {
// TODO: convert to logger
log.Printf("ERROR: MATOMO_DOMAIN was not set, so events will not be tracked")
fmt.Fprintf(os.Stderr, "ERROR: MATOMO_DOMAIN was not set, so events will not be tracked\n")
}
// make sure they didn't put the matomo.php at the end
config.Domain = strings.TrimSuffix(config.Domain, "matomo.php")
config.SiteID = envHelper("MATOMO_SITE_ID", "")
config.AuthToken = envHelper("MATOMO_AUTH_TOKEN", "")
config.Rec = "1"
}
func envHelper(key, defaultValue string) string {
found := os.Getenv(key)
if found == "" {
found = defaultValue
}
return found
}
func init() {
Setup()
}