func httpClient(r *http.Request) *http.Client { ctx, _ := context.WithTimeout(appengine.NewContext(r), 10*time.Second) github := httputil.NewAuthTransportFromEnvironment(nil) return &http.Client{ Transport: &httputil.AuthTransport{ Token: github.Token, ClientID: github.ClientID, ClientSecret: github.ClientSecret, Base: &urlfetch.Transport{Context: ctx}, UserAgent: fmt.Sprintf("%s (+http://%s/-/bot)", appengine.AppID(ctx), r.Host), }, } }
func init() { http.Handle("/", handlerFunc(serveRoot)) http.Handle("/compile", handlerFunc(serveCompile)) http.Handle("/bot.html", handlerFunc(serveBot)) present.PlayEnabled = true if s := os.Getenv("CONTACT_EMAIL"); s != "" { contactEmail = s } if appengine.IsDevAppServer() { return } github := httputil.NewAuthTransportFromEnvironment(nil) if github.Token == "" || github.ClientID == "" || github.ClientSecret == "" { panic("missing GitHub metadata, follow the instructions on README.md") } }
http.Handle("/-/refresh", handlerFunc(serveRefresh)) if s := os.Getenv("CONTACT_EMAIL"); s != "" { contactEmail = s } } var ( contactEmail = "*****@*****.**" homeTemplate = parseTemplate("common.html", "index.html") packageTemplate = parseTemplate("common.html", "package.html") errorTemplate = parseTemplate("common.html", "error.html") templateFuncs = template.FuncMap{ "timeago": timeagoFn, "contactEmail": contactEmailFn, } github = httputil.NewAuthTransportFromEnvironment(nil) ) func parseTemplate(fnames ...string) *template.Template { paths := make([]string, len(fnames)) for i := range fnames { paths[i] = filepath.Join("assets/templates", fnames[i]) } t, err := template.New("").Funcs(templateFuncs).ParseFiles(paths...) if err != nil { panic(err) } t = t.Lookup("ROOT") if t == nil { panic(fmt.Sprintf("ROOT template not found in %v", fnames)) }