Skip to content

Commit

Permalink
Move version handler to http package
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Apr 3, 2022
1 parent 6463c28 commit fb69bf2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 1 addition & 4 deletions cmd/nanomdm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ func main() {
}
}

mux.HandleFunc(endpointAPIVersion, func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"version":"` + version + `"}`))
})
mux.HandleFunc(endpointAPIVersion, mdmhttp.VersionHandler(version))

rand.Seed(time.Now().UnixNano())

Expand Down
8 changes: 8 additions & 0 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ func BasicAuth(next http.Handler, username, password, realm string) http.Handler
next.ServeHTTP(w, r)
}
}

// VersionHandler returns a simple JSON response from a version string.
func VersionHandler(version string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"version":"` + version + `"}`))
}
}

0 comments on commit fb69bf2

Please sign in to comment.