about summary refs log tree commit diff stats
path: root/osversion.go
diff options
context:
space:
mode:
Diffstat (limited to 'osversion.go')
-rw-r--r--osversion.go27
1 files changed, 23 insertions, 4 deletions
diff --git a/osversion.go b/osversion.go
index 24ac2c5..6ecac9a 100644
--- a/osversion.go
+++ b/osversion.go
@@ -1,10 +1,29 @@
 package main
 
-import "net/http"
+import (
+	"errors"
+	"fmt"
+	"os/exec"
+	"strings"
+)
 
-// OSVersion handles the /<format>/osversion endpoint.
+// osVersionQuery handles the /<format>/osversion endpoint.
 // Responds with the OpenBSD version.
-func OSVersion(w http.ResponseWriter, r *http.Request, format string) error {
+func osVersionQuery(format string) ([]byte, error) {
+	out, err := exec.Command("/usr/bin/uname", "-a").Output()
+	if err != nil {
+		return nil, errors.New("Couldn't exec `uname -a`")
+	}
 
-	return nil
+	split := strings.Split(string(out), " ")
+
+	if format == "json" {
+		return []byte(fmt.Sprintf(`
+{
+	"os": "%s",
+	"version": "%s"
+}`, split[0], split[2])), nil
+	}
+
+	return []byte(fmt.Sprintf("%s %s", split[0], split[2])), nil
 }