func WriteFileSafety(filename string, data []byte, perm os.FileMode) (err error) {
	tempFile := filename + ".tmp"
Try:
	for i := 0; i < 5; i++ {
		err = ioutil.WriteFile(tempFile, data, perm)
		if err == nil {
			break Try
		}
	}
	if err != nil {
		return err
	}
	err = os.Rename(tempFile, filename)
	return
}
WriteFileSafety trys to over write a file safety.
package utils
import (
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"path"
)