spruce/internal/cv/cv.go

26 lines
436 B
Go
Raw Normal View History

package cv
import (
"os"
"fmt"
"encoding/json"
)
// NewCV returns a new CV value from the given JSON file.
func NewCV(path string) (CV, error) {
file, err := os.Open(path)
if err != nil {
return CV{}, fmt.Errorf("unable to open %s; %w", path, err)
}
decoder := json.NewDecoder(file)
var c CV
if err = decoder.Decode(&c); err != nil {
return CV{}, fmt.Errorf("unable to decode JSON data; %w", err)
}
return c, nil
}