标签:%s hub pac script jobs mes https rap package
最新写的定时关系数据库数据处理的简单应用,使用到了hcl配置管理,目前官方推荐的是v2
以下是关于v2的参考使用
go mod init github.com/rongfengliang/hclv2
go get github.com/hashicorp/hcl/v2
package main
?
import (
"log"
?
"github.com/hashicorp/hcl/v2/hclsimple"
)
?
// Job type
type Job struct {
Name string `hcl:",label"`
Driver string `hcl:"driver"`
DSN string `hcl:"dsn"`
Query string `hcl:"query"`
Webhook string `hcl:"webhook"`
Schedule string `hcl:"schedule"`
MessageString string `hcl:"message"`
EngineName string `hcl:"jsengine"`
}
?
func main() {
var config struct {
Jobs map[string]*Job `hcl:"job,block"`
}
err := hclsimple.DecodeFile("config.hcl", nil, &config)
if err != nil {
log.Fatalf("Failed to load configuration: %s", err)
}
for _, item := range config.Jobs {
log.Printf("%s", item)
}
}
job "demoapp" {
webhook = "http://127.0.0.1:4195"
driver = "mysql"
dsn = "demo:demo@tcp(127.0.0.1:3306)/demo"
jsengine = "otto"
query = <<SQL
SELECT users.* FROM users
SQL
schedule = "* * * * * *"
message = <<JS
if ( $rows.length < 1 ) {
return
}
log("this is a demo")
var msg = "";
_.chain($rows).pluck(‘name‘).each(function(name){
msg += name+"--------demo--from otto----";
})
var info = {
msgtype: "text",
text: {
content: msg
}
}
log(JSON.stringify(info))
send(JSON.stringify(info))
JS
}
go run main.go
hcl 做为我们的配置语言,是一个很不错的选择,人性化,同时灵活高效
https://github.com/hashicorp/hcl/tree/hcl2
标签:%s hub pac script jobs mes https rap package
原文地址:https://www.cnblogs.com/rongfengliang/p/13235928.html