about summary refs log tree commit diff stats
path: root/osversion.go
blob: 3ad501a8f5e90e8a2a340f72d1bd7dc11fc141d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import (
	"errors"
	"fmt"
	"os/exec"
	"strings"
)

// executes uname and responds with "$OS $VERSION" in []byte{}
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`")
	}

	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
}