package main
import (
"fmt"
"html/template"
"log"
"os"
)
type Link struct {
Text string
Href string
}
func main() {
const tpl = `
{{.Title}}
{{.Title}}
{{.Body}}
{{range .Items}}
{{else}}
no rows
{{end}}
`
check := func(err error) {
if err != nil {
log.Fatal(err)
}
}
t, err := template.New("webpage").Parse(tpl)
check(err)
appName := os.Getenv("FN_APP_NAME")
data := struct {
Title string
Body string
Items []Link
}{
Title: "My App",
Body: "This is my app. It may not be the best app, but it's my app. And it's multilingual!",
Items: []Link{
Link{"Ruby", fmt.Sprintf("/r/%s/ruby", appName)},
Link{"Node", fmt.Sprintf("/r/%s/node", appName)},
Link{"Python", fmt.Sprintf("/r/%s/python", appName)},
},
}
err = t.Execute(os.Stdout, data)
check(err)
}