From f49258375057a40e01753275fe37f1365140f00b Mon Sep 17 00:00:00 2001 From: Jesse Peterson Date: Tue, 23 Jul 2024 11:37:44 -0700 Subject: [PATCH] add http package --- http/http.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 http/http.go diff --git a/http/http.go b/http/http.go new file mode 100644 index 0000000..18b0495 --- /dev/null +++ b/http/http.go @@ -0,0 +1,14 @@ +// Package http includes handlers and utilties. +package http + +import "net/http" + +// JSONVersionHandler returns a simple JSON response from a version string. +// The returned JSON is in the form of `{"version":"v0.0.1"}`. +func JSONVersionHandler(version string) http.HandlerFunc { + bodyBytes := []byte(`{"version":"` + version + `"}`) + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.Write(bodyBytes) + } +}