a224283def
some other updates
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package runtime
|
||
|
||
import (
|
||
"apigo.cc/apigo/plugin"
|
||
"github.com/ssgo/u"
|
||
"runtime"
|
||
"time"
|
||
)
|
||
|
||
func init() {
|
||
plugin.Register(plugin.Plugin{
|
||
Id: "apigo.cc/apigo/plugins/runtime",
|
||
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 运行结果
|
||
"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...)
|
||
},
|
||
},
|
||
})
|
||
}
|