Skip to content

Commit 29b45a4

Browse files
tookyclaude
andcommitted
refactor: remove duplication between loadInputFromFile and loadInput
loadInputFromFile now delegates to loadInput after opening the file, eliminating the duplicated JSON unmarshal logic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 09e19b0 commit 29b45a4

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

cmd/kosli/evaluateInput.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,17 @@ func (o *evaluateInputOptions) run(out io.Writer) error {
8787
return evaluateAndPrintResult(out, o.policyFile, input, o.output, o.showInput)
8888
}
8989

90-
func loadInputFromFile(filePath string) (map[string]interface{}, error) {
91-
data, err := os.ReadFile(filePath)
90+
func loadInputFromFile(filePath string) (result map[string]interface{}, err error) {
91+
f, err := os.Open(filePath)
9292
if err != nil {
9393
return nil, fmt.Errorf("failed to read input file: %w", err)
9494
}
95-
var input map[string]interface{}
96-
if err := json.Unmarshal(data, &input); err != nil {
97-
return nil, fmt.Errorf("failed to parse input: %w", err)
98-
}
99-
return input, nil
95+
defer func() {
96+
if cerr := f.Close(); cerr != nil && err == nil {
97+
err = cerr
98+
}
99+
}()
100+
return loadInput(f)
100101
}
101102

102103
func loadInput(r io.Reader) (map[string]interface{}, error) {

0 commit comments

Comments
 (0)