Compare commits

...

3 commits
main ... vet

Author SHA1 Message Date
Felix Niederwanger 748438eb3b
Add vet
Adds rule for running go vet.
2024-02-08 18:23:24 +01:00
Felix Niederwanger d5f79eae01 Merge pull request 'Add default page' (#20) from default into main
Reviewed-on: https://codeberg.org/grisu48/weblug/pulls/20
2023-11-25 22:13:14 +00:00
Felix Niederwanger 9713b0d2c1
Add default page
The default page handler now also accepts / as URL path for the default
page.
2023-11-25 23:12:51 +01:00
2 changed files with 14 additions and 5 deletions

View file

@ -30,3 +30,6 @@ tasks:
- test -f weblug
cmds:
- sudo bash -c "cd test && ./blackbox.sh"
vet:
cmds:
- go vet ./...

View file

@ -101,11 +101,9 @@ func main() {
}
// Create default handlers
http.HandleFunc("/", createDefaultHandler())
http.HandleFunc("/health", createHealthHandler())
http.HandleFunc("/health.json", createHealthHandler())
http.HandleFunc("/index", createDefaultHandler())
http.HandleFunc("/index.htm", createDefaultHandler())
http.HandleFunc("/index.html", createDefaultHandler())
http.HandleFunc("/robots.txt", createRobotsHandler())
// Register hooks
@ -223,8 +221,16 @@ func createHealthHandler() Handler {
func createDefaultHandler() Handler {
return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
fmt.Fprintf(w, "weblug - webhook receiver program\nSee https://codeberg.org/grisu48/weblug\n")
if r.URL.Path == "/" || r.URL.Path == "/index.txt" {
w.WriteHeader(200)
fmt.Fprintf(w, "weblug - webhook receiver program\nhttps://codeberg.org/grisu48/weblug\n")
} else if r.URL.Path == "/index.htm" || r.URL.Path == "/index.html" {
w.WriteHeader(200)
fmt.Fprintf(w, "<!DOCTYPE html><html><head><title>weblug</title></head>\n<body><p><a href=\"https://codeberg.org/grisu48/weblug\">weblug</a> - webhook receiver program</p>\n</body></html>")
} else {
w.WriteHeader(404)
fmt.Fprintf(w, "not found\n")
}
}
}