-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (44 loc) · 996 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
51
package main
import (
"html/template"
"log"
"net/http"
)
type templateData struct {
Path string
Docs string
Code string
}
const docRedirect = "https://godoc.formulabun.club/pkg/go.formulabun.club"
const codeRedirect = "https://github.com/formulabun"
const htmlPage = `<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="go.formulabun.club{{.Path}} git {{.Code}}{{.Path}}">
<meta http-equiv="refresh" content="0; url={{.Docs}}{{.Path}}">
</head>
<body>
<a href="{{.Docs}}{{.Path}}">Redirecting to documentation.</a>
</body>
</html>`
var templ *template.Template
func handler(w http.ResponseWriter, r *http.Request) {
data := templateData{
r.URL.EscapedPath(),
docRedirect,
codeRedirect,
}
err := templ.Execute(w, data)
if err != nil {
log.Println(err)
}
}
func main() {
var err error
templ, err = template.New("redirect").Parse(htmlPage)
if err != nil {
panic(err)
}
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8001", nil))
}