github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/config/profile/json.go (about) 1 package profile 2 3 import ( 4 "fmt" 5 "io" 6 "os" 7 8 "github.com/lmorg/murex/utils/json" 9 ) 10 11 // ReadJson is a function for reading a JSON file from disk 12 func ReadJson(path string, v interface{}) error { 13 file, err := os.OpenFile(path, os.O_RDONLY, 0640) 14 if err != nil { 15 return fmt.Errorf("Cannot open `%s` for read: %s", path, err.Error()) 16 } 17 18 b, err := io.ReadAll(file) 19 if err != nil { 20 return fmt.Errorf("Cannot read contents of `%s`: %s", path, err.Error()) 21 } 22 23 err = json.UnmarshalMurex(b, v) 24 if err != nil { 25 return fmt.Errorf("Cannot unmarshal `%s`: %s", path, err.Error()) 26 } 27 28 return nil 29 }