8 // NewFileUtil creates new file util
9 func NewFileUtil(localDir string) *FileUtil {
10 return &FileUtil{localDir}
13 // SaveBlockFile saves block file
14 func (f *FileUtil) SaveBlockFile(filename string, data interface{}) (bool, error) {
15 filename = f.LocalDir + filename + ".json"
16 saveData, err := json.Marshal(data)
21 err = ioutil.WriteFile(filename, saveData, 0644)
29 // GetJson read json file
30 func (f *FileUtil) GetJson(filename string) (json.RawMessage, error) {
31 filename = f.LocalDir + filename + ".json"
32 return ioutil.ReadFile(filename)
35 // Json2Struct transform json to struct
36 func Json2Struct(data json.RawMessage, resp interface{}) error {
37 return json.Unmarshal(data, &resp)
40 // Struct2Json transform struct to json
41 func Struct2Json(theStruct interface{}) (json.RawMessage, error) {
42 return json.Marshal(theStruct)