使用haproxy golang config-parser 包生成haproxy 配置
2021/12/11 6:19:41
本文主要是介绍使用haproxy golang config-parser 包生成haproxy 配置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
以下只是简单使用,具体复杂操作建议好好学习下haproxy的配置文件说明
demo 代码
- go mod
module demoapp
go 1.16
require github.com/haproxytech/config-parser/v4 v4.0.0-rc2 // indirect
- main.go
package main
import (
"log"
parser "github.com/haproxytech/config-parser/v4"
"github.com/haproxytech/config-parser/v4/options"
"github.com/haproxytech/config-parser/v4/parsers/http/actions"
)
const (
Mydemo = "demoapp"
)
func main() {
p, err := parser.New(options.String(""))
if err != nil {
log.Printf("some rong %s", err.Error())
}
httpRequestActionDeny := &actions.Deny{
DenyStatus: "0",
Cond: "unless",
CondTest: "{ src 127.0.0.1 }",
}
p.SectionsCreate(parser.Backends, Mydemo)
err = p.Insert(parser.Backends, Mydemo, "http-request", httpRequestActionDeny)
if err != nil {
log.Printf("some demo %s", err.Error())
}
err = p.Insert(parser.Backends, Mydemo, "http-request", httpRequestActionDeny, 1)
if err != nil {
log.Printf("some demo %s", err.Error())
}
result := p.String()
log.Println(result)
p.Save("demoapp4.cfg")
}
效果
说明
haproxy 的 client native 以及dataplan 都是很值得学习参考的
参考资料
https://github.com/haproxytech/config-parser
https://github.com/haproxytech/client-native
https://github.com/haproxytech/dataplaneapi
这篇关于使用haproxy golang config-parser 包生成haproxy 配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26解决google chrome helper 内存占用较高!
- 2024-04-01got an unexpected keyword argument
- 2024-03-30维多利亚的秘密 golang入坑系统
- 2024-03-29mongodb sort by date
- 2024-03-29go swagger
- 2024-03-25mongodb cdc
- 2024-03-25how to use go in vscode
- 2024-03-22mongooseserverselectionerror: connect econnrefused ::1:27017
- 2024-03-21pymongo insert_many
- 2024-03-18projection mongodb