代码拉取完成,页面将自动刷新
package easyjs
import (
"os"
"os/exec"
"time"
"gitee.com/haodreams/golib/logs"
"gitee.com/haodreams/libs/config"
"gitee.com/haodreams/libs/easy"
"gitee.com/haodreams/libs/routine"
"github.com/atotto/clipboard"
ping "github.com/prometheus-community/pro-bing"
)
type OS struct {
}
// 是否是工作日
func (m *OS) IsWorkday() bool {
lines, err := easy.ReadLines("data/holiday.csv")
if err == nil {
if len(lines) >= 0 {
now := easy.FormatNow(easy.YMD)
for _, line := range lines {
if line == now {
return false
}
}
}
}
// 获取当前工作日
day := time.Now().Weekday()
if day == 0 || day == 6 {
return false // 示例代码,返回 false 表明是周六或周日,非工作日
}
return true // 示例代码,返回 true 表明是工作日
}
// 复制到剪切板
func (m *OS) Copy(text string) {
clipboard.WriteAll(text)
}
func (m *OS) Ping(host string) int {
pinger, err := ping.NewPinger(host)
if err != nil {
return 0
}
pinger.SetPrivileged(true)
pinger.Count = 1
pinger.Timeout = time.Second
err = pinger.Run()
if err != nil {
return 0
}
stats := pinger.Statistics()
if stats.PacketsRecv == 0 {
return 0
}
return 1
}
/**
* @description: 获取配置文件
* @param {string} key
* @return {*}
*/
func (m *OS) GetValue(key string) string {
return config.String(key)
}
// 系统退出函数
func (m *OS) Exit() {
routine.Stop()
}
func (m *OS) SaveConfig() any {
return config.Save()
}
// 执行命令
func (m *OS) Exec(cmd ...string) {
if len(cmd) == 0 {
return
}
command := exec.Command(cmd[0], cmd[1:]...)
command.Stdout = os.Stdout
command.Stderr = os.Stderr
err := command.Run()
if err != nil {
logs.Warn(err)
}
}
func (m *OS) Sleep(ms int) {
if ms == 0 {
time.Sleep(time.Millisecond * 1000)
return
}
time.Sleep(time.Millisecond * time.Duration(ms))
}
// 获取一个进程的PID
func (m *OS) Kill(pid int) any {
process, err := os.FindProcess(int(pid))
if err != nil {
return err.Error()
}
err = process.Kill()
if err != nil {
return err.Error()
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。