lucas
2 weeks ago
8 changed files with 173 additions and 34 deletions
@ -0,0 +1,14 @@ |
|||
package monitors |
|||
|
|||
type CommonMonitorMonitor struct { |
|||
*MonitorHelper |
|||
} |
|||
|
|||
func (the *CommonMonitorMonitor) RegisterFun(fun func()) { |
|||
the.registerFun(fun) |
|||
} |
|||
|
|||
func (the *CommonMonitorMonitor) Start() { |
|||
the.initial() |
|||
the.monitorStart() |
|||
} |
@ -0,0 +1,53 @@ |
|||
package utils |
|||
|
|||
import ( |
|||
"fmt" |
|||
"log" |
|||
"os" |
|||
) |
|||
|
|||
func SaveCache2File(cacheStr string, fileName string) error { |
|||
// 打开文件,如果文件不存在则创建
|
|||
file, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) |
|||
if err != nil { |
|||
log.Println("Error opening file:", err) |
|||
return err |
|||
} |
|||
defer file.Close() |
|||
|
|||
// 将变量写入文件
|
|||
_, err = file.WriteString(cacheStr) |
|||
if err != nil { |
|||
log.Println("Error writing to file:", err) |
|||
} |
|||
return err |
|||
|
|||
} |
|||
|
|||
func ReadCache2File(fileName string) (string, error) { |
|||
// 打开文件
|
|||
file, err := os.Open(fileName) |
|||
if err != nil { |
|||
log.Println("Error opening file:", err) |
|||
return "", err |
|||
} |
|||
defer file.Close() |
|||
|
|||
// 读取文件内容
|
|||
var content string |
|||
_, err = fmt.Fscanf(file, "%s", &content) |
|||
if err != nil { |
|||
log.Println("Error reading from file:", err) |
|||
} |
|||
return content, err |
|||
} |
|||
|
|||
func FileExists(filePath string) bool { |
|||
_, err := os.Stat(filePath) |
|||
if err != nil { |
|||
if os.IsNotExist(err) { |
|||
return false |
|||
} |
|||
} |
|||
return true |
|||
} |
Loading…
Reference in new issue