Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add healthcheck endpoint #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Usage of ./go-webring
-v, --validationlog string Path to validation log, see docs for requirements (default "validation.log")
```

This webring implementation handles four paths:
This webring implementation handles five paths:
- **Root:** returns the home page template replacing the string "`{{ . }}`" with
an HTML table of ring members
- **Next:** returns a 302 redirect pointing to the next site in the list
Expand All @@ -36,6 +36,8 @@ This webring implementation handles four paths:
specified in the command line flags
- For example, with `-v validationlog -h example.com`, the path would be
`example.com/validationlog`
- **Healthcheck:** returns a 204 (no content) response, which can be used to
check whether the webring is up.

The **next** and **previous** paths require a `?host=` parameter containing a
URL-encoded URI of the site being visited. For example, if Sam is a member of a
Expand Down
4 changes: 4 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ func (m model) notFound(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte(*m.notFoundHtml))
}
}

func (m model) healthCheck(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusNoContent)
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func main() {
mux.HandleFunc("/previous", m.previous)
mux.HandleFunc("/random", m.random)
mux.HandleFunc("/"+filepath.Base(*flagValidationLog), m.validationLog)
mux.HandleFunc("/healthcheck", m.healthCheck)

fileHandler := http.StripPrefix("/static/", http.FileServer(http.Dir("static")))
mux.Handle("/static/", fileHandler)
Expand Down