photoprism/pkg/vector/alg/json_importer.go
Michael Mayer a2b7615c93 Go: Apply go fix modernizations across backend packages
Run `go fix ./...` and keep mechanical modernization updates.

- Replace `interface{}` with `any` in signatures and local types
- Apply formatter/style cleanups from go1.26 tooling
- Keep `omitempty` behavior-preserving simplifications suggested by fix
- No functional feature changes intended

Validation:
- go test ./... -run '^$' -count=1 (Go 1.26.0)
- GOTOOLCHAIN=go1.24.10 go test ./... -run '^$' -count=1

Signed-off-by: Michael Mayer <michael@photoprism.app>
2026-02-20 03:54:33 +01:00

52 lines
853 B
Go

package alg
import (
"encoding/json"
"os"
)
type jsonImporter struct{}
// JsonImporter returns an Importer that reads vectors from JSON files.
func JsonImporter() Importer {
return &jsonImporter{}
}
func (i *jsonImporter) Import(file string, start, end int) ([][]float64, error) {
if start < 0 || end < 0 || start > end {
return [][]float64{}, errInvalidRange
}
f, err := os.ReadFile(file) //nolint:gosec // caller controls path
if err != nil {
return [][]float64{}, err
}
var (
d = make([][]float64, 0)
s = end - start + 1
g = make([]float64, 0, s)
c int
)
err = json.Unmarshal(f, &d)
if err != nil {
return [][]float64{}, err
}
for i := range d {
c = 0
for j := start; j <= end; j++ {
g[c] = d[i][j]
c++
}
d[i] = make([]float64, 0, s)
for j := range s {
d[i][j] = g[j]
}
}
return d, nil
}