-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (45 loc) · 1002 Bytes
/
main.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
48
49
50
package main
import (
"flag"
"fmt"
"html/template"
"log"
"net/http"
"github.com/as27/donottrack"
)
var (
flagPort = flag.String("port", ":1313", "change the port of the server")
)
func main() {
flag.Parse()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := struct {
Name string
Foo string
DNT bool // include a boolean field for your template
}{
"Username",
"foo",
donottrack.IsSet(r), // call the IsSet function here
}
t, err := template.New("webpage").Parse(htmlTemplate)
if err != nil {
log.Fatal("error parsing template", err)
}
err = t.Execute(w, data)
if err != nil {
log.Fatal("error executing template", err)
}
})
fmt.Printf("serving at http://localhost%s\n", *flagPort)
err := http.ListenAndServe(*flagPort, nil)
if err != nil {
fmt.Println(err)
}
}
const htmlTemplate = `<html><body>
{{ if not .DNT }}
<p>Your external code for analytics or ads comes here</p>
{{ end }}
<p>my page</p>
</body></html>`