Update go tmpl name

This commit is contained in:
vinchent 2024-08-03 22:26:40 +02:00
parent 29902fc2f1
commit 0bb8fc7116
6 changed files with 104 additions and 11 deletions

53
.air.toml Normal file
View File

@ -0,0 +1,53 @@
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format
# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"
[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ./cmd/web/"
# Binary file yields from `cmd`.
bin = "tmp main"
# Customize binary.
full_bin = "STRIPE_SECRET= STRIPE_KEY= ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "gohtml"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# Exclude specific regular expressions.
exclude_regex = []
# Exclude unchanged files.
exclude_unchanged = true
# Follow symlink for directories
follow_symlink = true
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = true
# Delay after sending Interrupt signal
kill_delay = 500 # ms
[log]
# Show log time
time = false
[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"
[misc]
# Delete tmp directory on exit
clean_on_exit = true

View File

@ -1,7 +1,11 @@
package main
import "net/http"
import (
"net/http"
)
func (app *application) VirtualTerminal(w http.ResponseWriter, r *http.Request) {
return
if err := app.renderTemplate(w, r, "terminal", nil); err != nil {
app.errorLog.Println(err)
}
}

View File

@ -40,7 +40,7 @@ func (app *application) renderTemplate(
) error {
var t *template.Template
var err error
templateToRender := fmt.Sprintf("templates/%s.page.tmpl", page)
templateToRender := fmt.Sprintf("templates/%s.page.gohtml", page)
_, templateInMap := app.templateCache[templateToRender]
@ -79,15 +79,15 @@ func (app *application) parseTemplate(
// build partials
if len(partials) > 0 {
for i, x := range partials {
partials[i] = fmt.Sprintf("tempaltes/%s.partial.tmpl", x)
partials[i] = fmt.Sprintf("tempaltes/%s.partial.gohtml", x)
}
t, err = template.New(fmt.Sprintf("%s.page.tmpl", page)).
t, err = template.New(fmt.Sprintf("%s.page.gohtml", page)).
Funcs(functions).
ParseFS(templateFS, "templates/base.layout.tmpl", strings.Join(partials, ","), templateToRender)
ParseFS(templateFS, "templates/base.layout.gohtml", strings.Join(partials, ","), templateToRender)
} else {
t, err = template.New(fmt.Sprintf("%s.page.tmpl", page)).
t, err = template.New(fmt.Sprintf("%s.page.gohtml", page)).
Funcs(functions).
ParseFS(templateFS, "templates/base.layout.tmpl", templateToRender)
ParseFS(templateFS, "templates/base.layout.gohtml", templateToRender)
}
if err != nil {
app.errorLog.Println(err)

View File

@ -0,0 +1,30 @@
{{ define "base" }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous">
<title>
{{ block "title" . }}
{{ end }}
</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">{{ block "content" . }} {{ end }}</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
{{ block "js" . }}
{{ end }}
</body>
</html>
{{ end }}

View File

@ -1,3 +0,0 @@
{{define "base"}}
{{end}}

View File

@ -0,0 +1,9 @@
{{ template "base" . }}
{{ define "title" }}
Virtual Terminal
{{ end }}
{{ define "content" }}
<h2>Virtual Terminal</h2>
{{ end }}
{{ define "js" }}
{{ end }}