Files
coredns-web-ui/version.go
T
bryanpedini 7089a6f408 build: add makefile, dockerfile, ci and development stack
- build: add makefile, dockerfile, ci and development stack
- feat(config): add environment configuration and logger
- feat(server): add server lifecycle with health and version routes
- feat(db): add connection, contract check, migrations and stores
- feat(cli): add command dispatch and user management
- test(db): add integration tests against mysql
2026-11-19 15:46:12 +01:00

47 lines
1.1 KiB
Go

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2026 Bryan Joshua Pedini
package main
import (
"bytes"
_ "embed"
"html/template"
"io"
"net/http"
)
var APP_VERSION = "latest"
var COMMIT_ID = "undefined"
//go:embed templates/html/version.html
var versionHTML string
var versionTemplate = template.Must(template.New("version.html").Parse(versionHTML))
type versionPage struct {
Name string
Version string
Commit string
}
func versionLine() string {
return "coredns-web-ui " + APP_VERSION + " " + COMMIT_ID
}
func renderVersionPage(w io.Writer, name string) error {
return versionTemplate.Execute(w, versionPage{Name: name, Version: APP_VERSION, Commit: COMMIT_ID})
}
func (s *WebServer) handleVersion(w http.ResponseWriter, r *http.Request) {
var buf bytes.Buffer
if err := renderVersionPage(&buf, s.cfg.AppName); err != nil {
s.log.ErrorContext(r.Context(), "render version page failed", "error", err)
http.Error(w, "internal server error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(buf.Bytes())
}