mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2026-02-02 11:25:10 +01:00
24 lines
459 B
Go
24 lines
459 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func ParseFile[T any](filePath string) (result T, err error) {
|
|
file, err := os.Open(filePath)
|
|
if err != nil {
|
|
return result, fmt.Errorf("failed to open file %s: %w", filePath, err)
|
|
}
|
|
defer file.Close()
|
|
|
|
decoder := json.NewDecoder(file)
|
|
|
|
err = decoder.Decode(&result)
|
|
if err != nil {
|
|
return result, fmt.Errorf("failed to decode JSON from file %s: %w", filePath, err)
|
|
}
|
|
|
|
return result, nil
|
|
}
|