Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
fever-ch
GitHub Repository: fever-ch/go-google-sites-proxy
Path: blob/master/proxy/redirectpage.go
508 views
1
package proxy
2
3
import (
4
"bytes"
5
"github.com/fever-ch/go-google-sites-proxy/blob"
6
"github.com/fever-ch/go-google-sites-proxy/common"
7
"html/template"
8
"net/http"
9
)
10
11
const movedPageTmpl = `<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
12
<html><head>
13
<Title>Moved</Title>
14
</head><body>
15
<h1>Moved</h1>
16
<p>This page has moved to <a href="{{.Dest}}"">{{.Dest}}</a>.</p>
17
<hr>
18
</body></html>`
19
20
func movedPage(code int, destRoot string) func(request *http.Request) *Page {
21
type MovedPage struct {
22
Dest string
23
ProgramInfo common.ProgramInfoStruct
24
}
25
26
t := template.New("")
27
tt, _ := t.Parse(movedPageTmpl)
28
29
return func(request *http.Request) *Page {
30
fullDest := destRoot + request.URL.Path
31
hdrs := make(map[string](string))
32
hdrs["Location"] = fullDest
33
34
var doc bytes.Buffer
35
36
tt.Execute(&doc, MovedPage{fullDest, common.ProgramInfo})
37
38
return &Page{code, hdrs, blob.NewRawBlob([]byte(doc.String())), true}
39
}
40
}
41
42