diff --git a/Dockerfile b/Dockerfile index a2a9762..f982e78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,8 @@ WORKDIR /app ENV GOFLAGS="-tags=linux,libsqlite3" RUN apk add --no-cache git gcc musl-dev RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main sqlite-dev -ADD . /app +ADD *.go go.mod go.sum /app/ +ADD templates/ /app/templates/ RUN go test -cover ./... RUN go build -ldflags '-w -s' -o goshort diff --git a/templates.go b/templates.go index 37626b3..7f33d0e 100644 --- a/templates.go +++ b/templates.go @@ -1,6 +1,7 @@ package main import ( + _ "embed" "html/template" "log" "strings" @@ -17,55 +18,24 @@ func init() { } } -const listTemplateString = ` - - - -Short URLs -

Short URLs

- - -{{range .}}{{end}} -
slugurlhits
{{.Slug}}{{.URL}}{{.Hits}}
- -` +//go:embed templates/list.gohtml +var listTemplateString string func initListTemplate() (err error) { listTemplate, err = template.New("List").Parse(strings.TrimSpace(listTemplateString)) return } -const urlFormTemplateString = ` - - - -{{.Title}} -

{{.Title}}

-
-{{range .Fields}}

{{end}} - -
- -` +//go:embed templates/urlform.gohtml +var urlFormTemplateString string func initURLFormTemplate() (err error) { urlFormTemplate, err = template.New("UrlForm").Parse(strings.TrimSpace(urlFormTemplateString)) return } -const textFormTemplateString = ` - - - -{{.Title}} -

{{.Title}}

-
-{{range .Fields}}

{{end}} -{{range .TextAreas}}

{{end}} - -
- -` +//go:embed templates/textform.gohtml +var textFormTemplateString string func initTextFormTemplate() (err error) { textFormTemplate, err = template.New("TextForm").Parse(strings.TrimSpace(textFormTemplateString)) diff --git a/templates/list.gohtml b/templates/list.gohtml new file mode 100644 index 0000000..0a3dcc8 --- /dev/null +++ b/templates/list.gohtml @@ -0,0 +1,19 @@ + + + + +Short URLs +

Short URLs

+ + + + + + + + + +{{range .}}{{end}} + +
slugurlhits
{{.Slug}}{{.URL}}{{.Hits}}
+ \ No newline at end of file diff --git a/templates/textform.gohtml b/templates/textform.gohtml new file mode 100644 index 0000000..0e9abc9 --- /dev/null +++ b/templates/textform.gohtml @@ -0,0 +1,12 @@ + + + + +{{.Title}} +

{{.Title}}

+
+{{range .Fields}}
{{end}} +{{range .TextAreas}}
{{end}} + +
+ \ No newline at end of file diff --git a/templates/urlform.gohtml b/templates/urlform.gohtml new file mode 100644 index 0000000..ee67f7b --- /dev/null +++ b/templates/urlform.gohtml @@ -0,0 +1,11 @@ + + + + +{{.Title}} +

{{.Title}}

+
+{{range .Fields}}
{{end}} + +
+ \ No newline at end of file