clessli / bifrost Goto Github PK
View Code? Open in Web Editor NEWWeb服务器配置文件(Nginx config等)解析工具,提供配置文件展示和修改接口
License: MIT License
Web服务器配置文件(Nginx config等)解析工具,提供配置文件展示和修改接口
License: MIT License
json.Marshal可以直接将Config编码为json格式,如何将json解码成Config结构体呢?
server {
server_name test.xxxx.com;
listen 80;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_protocol;
proxy_set_header X-Rewrite-URL $request_uri;
location /test/ {
set_by_lua_block $foo {
local ok, err = pcall(require("phases_modules").set_process)
if not ok then
local emsg = "[LUA Framework], set_process failed."
ngx.log(ngx.ERR, emsg, err)
end
}
if ($request_uri !~* ^/test-resource/goofy/(.*)$ ) {
rewrite ^/test-resource/(.*)$ /test-resource/goofy/$1 break;
}
proxy_pass http://test2.xxx.com;
}
}
func main() {
nginxConfFromPath, err := configuration.NewConfigurationFromPath("/Users/catch/Desktop/test.nginx")
if err != nil {
panic(err)
}
fmt.Println(string(nginxConfFromPath.Json()))
}
panic: runtime error: index out of range [-1]
goroutine 1 [running]:
github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/loader.(*loader).loadFromConfigPosition(0xc000023040, 0x41a1fab, 0x23, 0x0, 0x0, 0x0, 0x0)
/Users/catch/go/src/github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/loader/loader.go:249 +0xd45
github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/loader.(*loader).LoadFromFilePath(0xc000023040, 0x41a1fab, 0x23, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/catch/go/src/github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/loader/loader.go:43 +0x32f
github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/configuration.NewConfigurationFromPath(0x41a1fab, 0x23, 0xc000117f78, 0x400b465, 0xc000070058, 0x0)
/Users/catch/go/src/github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/configuration/configuration.go:292 +0x92
main.main()
/Users/catch/Documents/code/deliver/go/plugin.go:119 +0x3a
当前Configuration指提供Json等方法输出序列化的nginx配置,能否提供将 type configuration struct {
config *parser.Config
rwLocker *sync.RWMutex
loopPreventer loop_preventer.LoopPreventer
utils.ConfigFingerprinter
}中的config导出的接口
请问 , 这个怎么使用 , 有相关文档吗
大佬,你的这个解析方式很巧妙,非常适合处理nginx配置,最近正在研究
在学习的过程中,发现一个问题,通常include下会放很多server的配置,如何方便解析和修改数据呢,由于 Children是个接口类型,要解析下层只能类型断言,这现一层层断言层次比较深,有什么好办法不
`
config, _ := resolv.Load("../test/nginx.conf")
for _, k := range config.Children {
switch k.(type) {
//case *resolv.Events:
//k.(*resolv.Events).Add(&resolv.Key{Name: "xx", Value: "yy"})
case *resolv.Http:
for _, p := range k.(*resolv.Http).Children {
switch p.(type) {
case *resolv.Include:
for _, q := range p.(*resolv.Include).Children {
switch q.(type) {
case *resolv.Config:
fmt.Println(q.(*resolv.Config).Name, q.(*resolv.Config).Value)
}
}
}
}
}
}
`
server_name ~^xxx[1-4]\.xxxxx\.com$
另外,如果server_name中使用正则,如上面这样,json.Marshal(conf) 会报错:
json: error calling MarshalJSON for type *resolv.Key: invalid character '.' in string escape code
看能解决不
有相关使用手册吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.