about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2020-05-11 02:34:19 -0400
committerBen Morrison <ben@gbmor.dev>2020-05-11 02:34:19 -0400
commit65986b345f9e8ecf7e75f58fc1b2936a397e9520 (patch)
treea5a1d29739ba7f87ae4132e051fa561280f324f7
parent4c827c826091facf38b33e5e828bc22150972450 (diff)
downloadapi-65986b345f9e8ecf7e75f58fc1b2936a397e9520.tar.gz
ignoring hidden directories in user count, changed error message to specify it came from user count query
-rw-r--r--usercount.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/usercount.go b/usercount.go
index 180c573..37b8697 100644
--- a/usercount.go
+++ b/usercount.go
@@ -11,10 +11,18 @@ import (
 func userCountQuery(format string) ([]byte, error) {
 	ls, err := exec.Command("/bin/ls", "/home").Output()
 	if err != nil {
-		return nil, fmt.Errorf("Couldn't execute ls: %w", err)
+		return nil, fmt.Errorf("User Count Query: %w", err)
 	}
 
 	split := strings.Fields(string(ls))
+	total := 0
+
+	for _, e := range split {
+		if strings.HasPrefix(e, ".") || strings.HasPrefix(e, "_") {
+			continue
+		}
+		total++
+	}
 
 	if format == "plain" {
 		return []byte(fmt.Sprintf("%v users\n", len(split))), nil
@@ -23,7 +31,7 @@ func userCountQuery(format string) ([]byte, error) {
 	out := fmt.Sprintf(`{
 	"userCount": "%v"
 }
-`, len(split))
+`, total)
 
 	return []byte(out), nil
 }