improve version handler
@@ -2,8 +2,6 @@ package main
import (
"net/http"
- "strconv"
- "strings"
)
type versionResult struct {
@@ -11,13 +9,6 @@ type versionResult struct {
Elektra elektraVersion `json:"elektra"`
}
-type elektraVersion struct {
- Version string `json:"version"`
- Major int `json:"major"`
- Minor int `json:"minor"`
- Micro int `json:"micro"`
-}
-
// getVersionHandler returns the current version of Elektra via
// JSON (see the `versionResult` struct).
//
@@ -26,35 +17,10 @@ type elektraVersion struct {
//
// Example: `curl localhost:33333/version`
func getVersionHandler(w http.ResponseWriter, r *http.Request) {
- kdb := getHandle(r)
-
- version, _ := kdb.Version()
-
- major, minor, micro := parseSemVer(version)
-
response := versionResult{
API: 1,
- Elektra: elektraVersion{
- Version: version,
- Major: major,
- Minor: minor,
- Micro: micro,
- },
+ Elektra: version,
}
writeResponse(w, response)
}
-
-func parseSemVer(version string) (major, minor, micro int) {
- parts := strings.SplitN(version, ".", 3)
-
- if len(parts) != 3 {
- return
- }
-
- major, _ = strconv.Atoi(parts[0])
- minor, _ = strconv.Atoi(parts[1])
- micro, _ = strconv.Atoi(parts[2])
-
- return
-}
