Compare commits

...

3 commits
v2 ... main

Author SHA1 Message Date
Magnus Åhall
40d5297042 And read CSS from embedded FS. Bumped to v5 2025-11-12 07:57:57 +01:00
Magnus Åhall
8bde331200 Show HTTP server error, bumped to v4 2025-11-12 07:56:22 +01:00
Magnus Åhall
9dafb5383d Use embedded index.html, bumped to v3 2025-11-12 07:55:03 +01:00

16
main.go
View file

@ -17,7 +17,7 @@ import (
"strings"
)
const VERSION = "v2"
const VERSION = "v5"
var (
flagVerbose bool
@ -49,7 +49,11 @@ func main() {
http.HandleFunc("/sites", actionSites)
log.Println("Listen on [::]:5123")
http.ListenAndServe("[::]:5123", nil)
err := http.ListenAndServe("[::]:5123", nil)
if err != nil {
log.Println(err)
os.Exit(1)
}
}
func replaceTilde(str string) string { // {{{
@ -69,10 +73,7 @@ func replaceTilde(str string) string { // {{{
func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{
var tmpl *template.Template
var err error
if false {
tmpl, err = template.ParseFS(fs, "static/html/index.html")
}
tmpl, err = template.ParseFiles("static/html/index.html")
tmpl, err = template.ParseFS(fs, "static/html/index.html")
if err != nil {
w.Write([]byte(err.Error()))
return
@ -87,8 +88,7 @@ func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{
func pageCSS(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Content-Type", "text/css")
//data, err := fs.ReadFile("static/css/main.css")
data, err := os.ReadFile("static/css/main.css")
data, err := fs.ReadFile("static/css/main.css")
if err != nil {
w.Write([]byte(err.Error()))
return