plugins/runtime/runtime.go

40 lines
900 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package runtime
import (
"apigo.cloud/git/apigo/plugin"
"github.com/ssgo/u"
"runtime"
"time"
)
func init() {
plugin.Register(plugin.Plugin{
Id: "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, args ...string) ([]string, error) {
return u.RunCommand(command, args...)
},
},
})
}