在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
写了一个可以用 go 来写脚本的工具:gosl代码和使用说明可以看这里: http://github.com/daviddengcn/gosl Go Search 已经完全用 gosl 来启动了。 相比 bash/Python 写脚本的好处:
这里贴一个简单的例子: #!/bin/gosl APPS := []string { "tocrawl", "crawler", "mergedocs", "indexer", } for { for _, app := range APPS { Printf("Running %s...\n", app) Bash(app) } } goslThis is an application that can make you write script with the Go language. It is NOT an interpreter but the pure Go. The preprocessor tranforms the script into a Go program, instantly compiles and runs. So it is almost same as the standard Go with the same efficiency. Benefit
Example
#!/bin/gosl import "encoding/json" toJson := func(lines []string) string { res, _ := json.Marshal(struct { Lines []string `json:"lines"` }{ Lines: lines, }) return string(res) } files := BashEval("ls -l %s", "/tmp/") Println(toJson(Split(files, "\n")))
Installation and UsageDownload and install the package
(Optional) Link to
|
Method | Description | Example |
---|---|---|
S |
Convert anything to a string
|
S(1234) == "123" |
I |
Convert anything to an int
|
I("1234") == 1234 |
BashEval |
Similar to bash backtick substitution. | lsstr := BashEval("ls -l") |
Exec |
Execute an command with arguments | err, code := Exec("rm", "-rf" "tmp") |
Bash |
Execute a bash line | err, code := Bash("rm -rf tmp") |
ScriptDir |
Returns the directory of the script | file := ScriptDir() + "/" + fn |
More functions are defined in package daviddengcn/gosl/builtin/ (godoc)
请发表评论