SaveJSONToFile() saves a json object to a file
(j any, dataDirPath, filePath string)
| 491 | |
| 492 | // SaveJSONToFile() saves a json object to a file |
| 493 | func SaveJSONToFile(j any, dataDirPath, filePath string) (err ErrorI) { |
| 494 | // convert the object into json bytes |
| 495 | jsonBytes, err := MarshalJSONIndent(j) |
| 496 | // if an error occurred during the conversion |
| 497 | if err != nil { |
| 498 | // exit with error |
| 499 | return |
| 500 | } |
| 501 | // attempt to write the json bytes to a json file at the path |
| 502 | if e := os.WriteFile(filepath.Join(dataDirPath, filePath), jsonBytes, os.ModePerm); e != nil { |
| 503 | // exit with error |
| 504 | return ErrWriteFile(e) |
| 505 | } |
| 506 | // exit |
| 507 | return |
| 508 | } |
| 509 | |
| 510 | // NewAny() converts a proto.Message into an anypb.Any type |
| 511 | func NewAny(message proto.Message) (*anypb.Any, ErrorI) { |
no test coverage detected