Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
fever-ch
GitHub Repository: fever-ch/go-google-sites-proxy
Path: blob/master/proxy/index.go
508 views
1
package proxy
2
3
import (
4
"github.com/fever-ch/go-google-sites-proxy/common"
5
"github.com/fever-ch/go-google-sites-proxy/common/config"
6
log "github.com/sirupsen/logrus"
7
"html/template"
8
"net/http"
9
)
10
11
const tmpl = `<!DOCTYPE html>
12
<html lang="en">
13
<head>
14
<Title>{{.ProgramInfo.Name}}</Title>
15
<meta charset="utf-8">
16
</head>
17
<body>
18
<h1>{{.ProgramInfo.Fullname}}</h1>
19
<ul>
20
{{range .Sites}}<li><a href="http://{{.HostField}}">{{if .DescriptionField}}{{.DescriptionField}}{{else}}{{.HostField}}{{end}}</a></li>{{end}}
21
</ul>
22
<br>
23
<br>
24
2017 Fever.ch - <a href="{{.ProgramInfo.ProjectURL}}">{{.ProgramInfo.Fullname}}</a>
25
</body>
26
</html>`
27
28
type indexStruct struct {
29
ProgramInfo common.ProgramInfoStruct
30
Sites []config.Site
31
}
32
33
func getIndex(configuration config.Configuration) *func(responseWriter http.ResponseWriter, request *http.Request) {
34
f := func(responseWriter http.ResponseWriter, req *http.Request) {
35
t := template.New("")
36
tt, _ := t.Parse(tmpl)
37
err := tt.Execute(responseWriter, indexStruct{common.ProgramInfo, configuration.Sites()})
38
if err != nil {
39
log.Warning("Problem rendering the template", err)
40
}
41
}
42
return &f
43
}
44
45