miki

Miki: personal wiki with the fmd markup format
git clone https://wtenison.com/repo/miki.git
Log | Files | Refs | README | LICENSE

files.go (653B)


      1 package filesystem
      2 
      3 import (
      4 	"encoding/json"
      5 	"fmt"
      6 	"os"
      7 	"path/filepath"
      8 )
      9 
     10 func ReadFileJSON(inputFilePath string, outputDataContainer any) error {
     11 
     12 	_fileName := filepath.Base(inputFilePath)
     13 	if filepath.Ext(_fileName) != ".json" {
     14 		return fmt.Errorf("ReadFileJSON:filepath.Ext:%s:invalid file extension", _fileName)
     15 	}
     16 
     17 	_fsData, _err := os.ReadFile(inputFilePath)
     18 	if _err != nil {
     19 		return fmt.Errorf("ReadFileJSON:os.ReadFile:%s:%s", inputFilePath, _err.Error())
     20 	}
     21 
     22 	if _err = json.Unmarshal(_fsData, &outputDataContainer); _err != nil {
     23 		return fmt.Errorf("ReadFileJSON:json.Unmarshal:%s:%s", inputFilePath, _err.Error())
     24 	}
     25 
     26 	return nil
     27 }