зеркало из https://github.com/golang/gddo.git
gddo-server: fetch Google Analytics account ID from metadata or env
Fixes #388 Change-Id: Ib57829af5b56636b29d7ac91293660d385401aa5 Reviewed-on: https://go-review.googlesource.com/20587 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Родитель
d0ea64afce
Коммит
309d40be40
|
@ -30,6 +30,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"google.golang.org/cloud/compute/metadata"
|
||||
|
||||
"github.com/golang/gddo/database"
|
||||
"github.com/golang/gddo/doc"
|
||||
"github.com/golang/gddo/gosrc"
|
||||
|
@ -834,6 +836,17 @@ func main() {
|
|||
doc.SetDefaultGOOS(*defaultGOOS)
|
||||
httpClient = newHTTPClient()
|
||||
|
||||
if metadata.OnGCE() {
|
||||
acct, err := metadata.ProjectAttributeValue("ga-account")
|
||||
if err != nil {
|
||||
log.Printf("querying metadata for ga-account: %v", err)
|
||||
} else {
|
||||
gaAccount = acct
|
||||
}
|
||||
} else {
|
||||
gaAccount = os.Getenv("GA_ACCOUNT")
|
||||
}
|
||||
|
||||
if err := parseHTMLTemplates([][]string{
|
||||
{"about.html", "common.html", "layout.html"},
|
||||
{"bot.html", "common.html", "layout.html"},
|
||||
|
|
Загрузка…
Ссылка в новой задаче