Merge branch 'email' of https://github.com/golang/gddo into email
diff --git a/talksapp/main.go b/talksapp/main.go
index 5ed7dbb..2ea5a2e 100644
--- a/talksapp/main.go
+++ b/talksapp/main.go
@@ -9,10 +9,12 @@
import (
"bytes"
+ "encoding/json"
"errors"
"fmt"
"html/template"
"io"
+ "log"
"net/http"
"os"
"path"
@@ -32,8 +34,8 @@
".slide": parsePresentTemplate("slides.tmpl"),
}
homeArticle = loadHomeArticle()
- contactEmail = "unknown@example.com"
- gitHubCredentials = ""
+ contactEmail = "golang-dev@googlegroups.com"
+ githubCredentials = parseGithubCredentials()
)
func init() {
@@ -43,6 +45,22 @@
present.PlayEnabled = true
}
+func parseGithubCredentials() string {
+ f, err := os.Open("secret.json")
+ if err != nil {
+ log.Fatalf("open github credentials file secret.json: %v", err)
+ }
+ defer f.Close()
+ var cred struct{ ClientID, ClientSecret string }
+ if err := json.NewDecoder(f).Decode(&cred); err != nil {
+ log.Fatalf("parse github credentials: %v", err)
+ }
+ if cred.ClientID == "" || cred.ClientSecret == "" {
+ log.Fatal("secret.json needs to define ClientID and ClientSecret")
+ }
+ return fmt.Sprintf("client_id=%s&client_secret=%s", cred.ClientID, cred.ClientSecret)
+}
+
func playable(c present.Code) bool {
return present.PlayEnabled && c.Play && c.Ext == ".go"
}
@@ -116,11 +134,11 @@
func (t transport) RoundTrip(r *http.Request) (*http.Response, error) {
r.Header.Set("User-Agent", t.ua)
- if r.URL.Host == "api.github.com" && gitHubCredentials != "" {
+ if r.URL.Host == "api.github.com" {
if r.URL.RawQuery == "" {
- r.URL.RawQuery = gitHubCredentials
+ r.URL.RawQuery = githubCredentials
} else {
- r.URL.RawQuery += "&" + gitHubCredentials
+ r.URL.RawQuery += "&" + githubCredentials
}
}
return t.rt.RoundTrip(r)
diff --git a/talksapp/secret.json b/talksapp/secret.json
new file mode 100644
index 0000000..979fe98
--- /dev/null
+++ b/talksapp/secret.json
@@ -0,0 +1,4 @@
+{
+ "ClientID": "",
+ "ClientSecret": ""
+}