-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1c7ff2e
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.6 | ||
*.8 | ||
*.o | ||
*.so | ||
*.cgo?.* | ||
_cgo_* | ||
_test* | ||
*.out | ||
_obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
application: repostats | ||
version: 1 | ||
runtime: go | ||
api_version: go1 | ||
|
||
default_expiration: "1d" | ||
|
||
handlers: | ||
- url: /.* | ||
script: _go_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{define "page"}} | ||
<!DOCTYPE HTML> | ||
|
||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<title>Account page: {{.Account}}</title> | ||
</head> | ||
|
||
<body> | ||
<p>Account page: {{.Account}}</p> | ||
|
||
<script> | ||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | ||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | ||
|
||
ga('create', '{{.Account}}', 'repostats.appengine.com/{{.Account}}'); | ||
// ga('send', 'pageview'); | ||
</script> | ||
</body> | ||
</html> | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package stats | ||
|
||
import ( | ||
"appengine" | ||
// "appengine/urlfetch" | ||
"html/template" | ||
"encoding/base64" | ||
// "crypto/md5" | ||
"net/http" | ||
"strings" | ||
"io" | ||
) | ||
|
||
const base64GifPixel = "R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" | ||
var pageTemplate, _ = template.New("page").ParseFiles("repostats/page.html") | ||
|
||
func init() { | ||
http.HandleFunc("/", handler) | ||
} | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
c := appengine.NewContext(r) | ||
c.Infof("Requested URL: %v", r.URL) | ||
|
||
// / -> redirect | ||
// /account -> account template | ||
// /account/page -> GIF hit | ||
params := strings.SplitN(strings.Trim(r.URL.Path,"/"), "/", 2) | ||
|
||
if len(params) == 0 { | ||
http.Redirect(w, r, "https://github.com/igrigorik/repostats", http.StatusFound) | ||
return | ||
} | ||
|
||
if len(params) == 1 { | ||
account := map[string]interface{}{"Account": params[0]} | ||
if err := pageTemplate.ExecuteTemplate(w, "page", account); err != nil { | ||
panic("Cannot execute template") | ||
} | ||
|
||
} else { | ||
w.Header().Set("Content-Type", "image/gif") | ||
w.Header().Set("Cache-Control", "no-cache") | ||
|
||
output, _ := base64.StdEncoding.DecodeString(base64GifPixel) | ||
io.WriteString(w, string(output)) | ||
} | ||
|
||
c.Infof("Params size: %v, %v", len(params), params) | ||
return | ||
} |