commit c19f28639f074e294d4f21425d3a45fb14cdead2
parent 7435a13e5f4d176db4421149b85e6d3319122c3a
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 29 Jun 2025 21:42:46 -0400
reflect helper now used only in one place
Diffstat:
3 files changed, 9 insertions(+), 42 deletions(-)
diff --git a/internal/output/json.go b/internal/output/json.go
@@ -3,9 +3,9 @@ package output
import (
"fmt"
+ "reflect"
+ "sort"
"strings"
-
- "git.sr.ht/~enckse/lockbox/internal/reflect"
)
// JSONModes are the JSON data output types for exporting/output of values
@@ -29,7 +29,13 @@ type (
// List will list the output modes on the struct
func (p JSONTypes) List() []string {
- return reflect.ListFields(p)
+ v := reflect.ValueOf(p)
+ var vals []string
+ for i := range v.NumField() {
+ vals = append(vals, fmt.Sprintf("%v", v.Field(i).Interface()))
+ }
+ sort.Strings(vals)
+ return vals
}
// ParseJSONMode handles detecting the JSON output mode
diff --git a/internal/reflect/core.go b/internal/reflect/core.go
@@ -1,19 +0,0 @@
-// Package reflect has reflection helpers
-package reflect
-
-import (
- "fmt"
- "reflect"
- "sort"
-)
-
-// ListFields will get the values of strings on an "all string" struct
-func ListFields(p any) []string {
- v := reflect.ValueOf(p)
- var vals []string
- for i := range v.NumField() {
- vals = append(vals, fmt.Sprintf("%v", v.Field(i).Interface()))
- }
- sort.Strings(vals)
- return vals
-}
diff --git a/internal/reflect/core_test.go b/internal/reflect/core_test.go
@@ -1,20 +0,0 @@
-package reflect_test
-
-import (
- "fmt"
- "testing"
-
- "git.sr.ht/~enckse/lockbox/internal/reflect"
-)
-
-type mock struct {
- Name string
- Field string
-}
-
-func TestListFields(t *testing.T) {
- fields := reflect.ListFields(mock{"abc", "xyz"})
- if len(fields) != 2 || fmt.Sprintf("%v", fields) != "[abc xyz]" {
- t.Errorf("invalid fields: %v", fields)
- }
-}