blob: ff354636a3bf3b3a5a4671d8958226740d423a76 (
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
29
|
package main
import (
"fmt"
"os/exec"
"strings"
)
// Just returns the number of directories in /home
// The assumption being, it's the number of human users.
func userCountQuery(format string) ([]byte, error) {
ls, err := exec.Command("ls", "/home").Output()
if err != nil {
return nil, fmt.Errorf("Couldn't execute ls: %w", err)
}
split := strings.Split(string(ls), " ")
if format == "plain" {
return []byte(fmt.Sprintf("%v users", len(split))), nil
}
out := fmt.Sprintf(`{
"userCount": "%v"
}
`, len(split))
return []byte(out), nil
}
|