-
Notifications
You must be signed in to change notification settings - Fork 2
/
podstat.go
47 lines (38 loc) · 1.02 KB
/
podstat.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
package main
import (
"log"
"net/http"
"net/url"
"os"
)
func redirectAndStore(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "http://devopsdeflope.ru/"+r.URL.Path[1:], http.StatusFound)
values := make(url.Values)
ga_cookie := "0"
xff_ip := r.Header.Get("X-Forwarded-For")
for i := range r.Cookies() {
if r.Cookies()[i].Name == "_ga" {
ga_cookie = r.Cookies()[i].Value
}
}
values.Set("v", "1")
values.Set("tid", "MO-41332661-1")
values.Set("cid", ga_cookie)
values.Set("t", "event")
values.Set("ea", "Download")
values.Set("el", r.URL.Path)
values.Set("ec", "Podcast")
if len(xff_ip) != 0 {
values.Set("utmip", xff_ip)
}
http.PostForm("http://www.google-analytics.com/collect", url.Values(values))
}
func rdrToDeflope(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "http://devopsdeflope.ru/", http.StatusFound)
}
func main() {
http.HandleFunc("/mp3/", redirectAndStore)
http.HandleFunc("/", rdrToDeflope)
log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
os.Exit(0)
}