You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package govue2
import ( "encoding/json" "io/ioutil" "os" "os/exec" "path/filepath" "strings" )
func pathExists(path string) bool { _, err := os.Stat(path) if err == nil { return true } if os.IsNotExist(err) { return false } return false }
var selfFilePath string
func getSelfFilePath() string { if selfFilePath == "" { file, err := exec.LookPath(os.Args[0]) if err != nil { return "" } path, err := filepath.Abs(file) if err != nil { return "" } i := strings.LastIndex(path, "/") if i < 0 { i = strings.LastIndex(path, "\\") } if i < 0 { return "" } selfFilePath, _ = filepath.Abs(string(path[0 : i+1])) } return selfFilePath }
func jsonToFile(file string, v interface{}) bool { data, err := json.Marshal(v) if err != nil { return false } return ioutil.WriteFile(file, data, 0644) == nil }
func jsonByFile(file string, v interface{}) { data, _ := ioutil.ReadFile(file) json.Unmarshal(data, v) }
|