2024-01-25 16:07:48 +08:00
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
|
|
import (
|
2024-06-26 12:17:41 +08:00
|
|
|
|
"apigo.cc/apigo/plugin"
|
2024-01-25 16:07:48 +08:00
|
|
|
|
"github.com/ssgo/u"
|
|
|
|
|
"runtime"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
plugin.Register(plugin.Plugin{
|
2024-06-26 12:17:41 +08:00
|
|
|
|
Id: "apigo.cc/apigo/plugins/runtime",
|
2024-01-25 16:07:48 +08:00
|
|
|
|
Name: "运行时支持",
|
|
|
|
|
Objects: map[string]interface{}{
|
|
|
|
|
// sleep 程序等待指定时间
|
|
|
|
|
// sleep ms 休眠时长,单位ms
|
|
|
|
|
"sleep": func(ms int) {
|
|
|
|
|
time.Sleep(time.Duration(ms) * time.Millisecond)
|
|
|
|
|
},
|
|
|
|
|
// os 获取操作系统名称
|
|
|
|
|
// os return 操作系统名称
|
|
|
|
|
"os": func() string {
|
|
|
|
|
return runtime.GOOS
|
|
|
|
|
},
|
|
|
|
|
// arch 获取操作系统构建版本
|
|
|
|
|
// arch return 操作系统构建版本
|
|
|
|
|
"arch": func() string {
|
|
|
|
|
return runtime.GOARCH
|
|
|
|
|
},
|
|
|
|
|
// shell 运行外部命令
|
|
|
|
|
// shell command 命令
|
|
|
|
|
// shell args 参数
|
|
|
|
|
// shell return 运行结果
|
2024-07-04 11:14:34 +08:00
|
|
|
|
"shell": func(command string, callback func(string), args ...string) ([]string, error) {
|
|
|
|
|
for i := 1; i <= 10; i++ {
|
|
|
|
|
callback(u.String(i))
|
|
|
|
|
time.Sleep(time.Millisecond * 200)
|
|
|
|
|
}
|
|
|
|
|
return nil, nil
|
|
|
|
|
//return u.RunCommand(command, args...)
|
2024-01-25 16:07:48 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|