-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheditor.go
More file actions
38 lines (30 loc) · 678 Bytes
/
editor.go
File metadata and controls
38 lines (30 loc) · 678 Bytes
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
package main
import (
"html/template"
"net/http"
"strings"
)
var editTemplate = template.Must(template.ParseFiles("static/index.html"))
// Example Jsonnet to show people on first visit
const defaultJsonnet = `local first = "hello";
{
second:: "world",
out: "%s %s!" % [first, self.second],
}`
type editData struct {
Code string
}
func HandleEditor(w http.ResponseWriter, r *http.Request) {
editData := editData{
Code: defaultJsonnet,
}
if strings.HasPrefix(r.URL.Path, "/j/") {
id := r.URL.Path[3:]
code, err := store.Get(id)
if err == nil {
editData.Code = code
}
}
// TODO: Add some error handling around
editTemplate.Execute(w, editData)
}