Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<img src="./logo/logo.png" style="width: 220px; margin: 30px" alt="Workflow Logo">
<img src="./logo/logo.svg" style="width: 220px; margin: 30px" alt="Workflow Logo">
<div align="center" style="max-width: 750px">
<a style="padding: 0 5px" href="https://goreportcard.com/report/github.com/luno/workflow"><img src="https://goreportcard.com/badge/github.com/luno/workflow"/></a>
<a style="padding: 0 5px" href="https://sonarcloud.io/summary/new_code?id=luno_workflow"><img src="https://sonarcloud.io/api/project_badges/measure?project=luno_workflow&metric=coverage"/></a>
Expand Down
45 changes: 5 additions & 40 deletions adapters/webui/internal/frontend/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,20 @@ package frontend

import (
_ "embed"
"html/template"
"net/http"
"strings"
"text/template"
Comment thread
andrewwormald marked this conversation as resolved.
)

// Embed the template file
//
//go:embed home.html
var homeTemplate string

//go:embed main.js
var mainJS string

func HomeHandlerFunc(paths Paths) http.HandlerFunc {
// Use [[ ]] delimiters so JSX {{ }} syntax passes through unmodified.
t := template.Must(template.New("home.html").Delims("[[", "]]").Parse(homeTemplate))
return func(w http.ResponseWriter, r *http.Request) {
t, err := template.New("home.html").Parse(homeTemplate)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

jsTemplate, err := template.New("main.js").Parse(mainJS)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// Build the JS using the provided paths
var builder strings.Builder
err = jsTemplate.Execute(&builder, struct {
Paths Paths
}{
Paths: paths,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

err = t.Execute(w, struct {
Paths Paths
Javascript template.JS
}{
Paths: paths,
Javascript: template.JS(builder.String()),
})
if err != nil {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := t.Execute(w, paths); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}
Expand Down
Loading
Loading