Update page contents

This commit is contained in:
2026-06-24 08:17:35 -04:00
parent cb53a00e27
commit 9b5cd0c611
2 changed files with 22 additions and 6 deletions

23
main.go
View File

@@ -19,8 +19,9 @@ var hjemTemplate string
var port = flag.Int("p", 1437, "set the port for hjem to use")
type HjemData struct {
OS string
Email string
OS string
Email string
Timezone string
}
func main() {
@@ -67,12 +68,26 @@ func main() {
}
}
user_tz := "UTC"
if tz := os.Getenv("TZ"); tz != "" {
user_tz = tz
} else if data, err := os.ReadFile("/etc/timezone"); err == nil {
if tz := strings.TrimSpace(string(data)); tz != "" {
user_tz = tz
}
} else if path, err := os.Readlink("/etc/localtime"); err == nil {
user_tz = filepath.Join(
filepath.Base(filepath.Dir(path)),
filepath.Base(path))
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
err := t.ExecuteTemplate(w, "hjem", HjemData{
OS: user_os,
Email: user_email,
OS: user_os,
Email: user_email,
Timezone: user_tz,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)