diff --git a/core/sys.go b/core/sys.go index 1236962..c5f90e7 100644 --- a/core/sys.go +++ b/core/sys.go @@ -36,7 +36,7 @@ func Daemon() { panic(err) } logs.Info(sillyGirl.Get("name", "傻妞") + "以静默形式运行") - WriteToFile(pidf, (fmt.Sprintf("%d", proc.Process.Pid))) + os.WriteFile(pidf, []byte(fmt.Sprintf("%d", proc.Process.Pid)), 0o644) os.Exit(0) } diff --git a/core/test.go b/core/test.go index 8b47b8b..b94979c 100644 --- a/core/test.go +++ b/core/test.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io/ioutil" + "os" "os/exec" "strings" "time" @@ -250,7 +251,7 @@ Alias=sillyGirl.service` s.Reply(data) return nil } - WriteToFile("/usr/lib/systemd/system/sillyGirl.service", (service)) + os.WriteFile("/usr/lib/systemd/system/sillyGirl.service", []byte(service), 0o644) exec.Command("systemctl", "disable", string(sillyGirl)).Output() exec.Command("systemctl", "enable", string(sillyGirl)).Output() return "电脑重启后生效。" diff --git a/core/utils.go b/core/utils.go deleted file mode 100644 index 4d57e23..0000000 --- a/core/utils.go +++ /dev/null @@ -1,18 +0,0 @@ -package core - -import ( - "fmt" - "os" -) - -func WriteToFile(fileName string, content string) error { - f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) - if err != nil { - fmt.Println("file create failed. err: " + err.Error()) - } else { - n, _ := f.Seek(0, os.SEEK_END) - _, err = f.WriteAt([]byte(content), n) - defer f.Close() - } - return err -}