9 // NewFileUtil creates new file util
10 func NewFileUtil(localDir string) *FileUtil {
11 return &FileUtil{localDir}
14 // SaveBlockFile saves block file
15 func (f *FileUtil) SaveBlockFile(filename string, data interface{}) (bool, error) {
16 filename = f.LocalDir + "/" + filename + ".json"
17 saveData, err := json.Marshal(data)
22 err = ioutil.WriteFile(filename, saveData, 0644)
30 // GetJson read json file
31 func (f *FileUtil) GetJson(filename string) (json.RawMessage, error) {
32 filename = f.LocalDir + "/" + filename + ".json"
33 return ioutil.ReadFile(filename)
36 // RemoveLocal deletes file
37 func (f *FileUtil) RemoveLocal(filename string) error {
38 return os.Remove(f.LocalDir + "/" + filename)
41 // Json2Struct transform json to struct
42 func Json2Struct(data json.RawMessage, resp interface{}) error {
43 return json.Unmarshal(data, &resp)
46 // Struct2Json transform struct to json
47 func Struct2Json(theStruct interface{}) (json.RawMessage, error) {
48 return json.Marshal(theStruct)