common WriteFile from resource fork

This commit is contained in:
Jeff Carr 2025-09-09 14:53:31 -05:00
parent ac5da98149
commit a641772159
1 changed files with 2 additions and 20 deletions

22
http.go
View File

@ -10,6 +10,7 @@ import (
"os"
"strings"
"go.wit.com/lib/protobuf/httppb"
"go.wit.com/log"
)
@ -79,32 +80,13 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if route == "/favicon.ico" {
writeFile(w, "ipv6.png")
httppb.WriteFile(w, resources, "ipv6.png")
return
}
log.Warn("BAD URL =", route)
}
func writeFile(w http.ResponseWriter, filename string) {
// fmt.Fprintln(w, "GOT TEST?")
fullname := "resources/" + filename
pfile, err := resources.ReadFile(fullname)
if err != nil {
log.Println("ERROR:", err)
// w.Write(pfile)
return
}
var repohtml string
repohtml = string(pfile)
if filename == "goReference.svg" {
w.Header().Set("Content-Type", "image/svg+xml")
}
fmt.Fprintln(w, repohtml)
log.Println("writeFile() found internal file:", filename)
}
// starts and sits waiting for HTTP requests
func startHTTP() {
http.HandleFunc("/", okHandler)