GithubHelp home page GithubHelp logo

clessli / bifrost Goto Github PK

View Code? Open in Web Editor NEW
39.0 3.0 11.0 1.06 MB

Web服务器配置文件(Nginx config等)解析工具,提供配置文件展示和修改接口

License: MIT License

Go 93.22% Shell 4.92% Makefile 1.86% Batchfile 0.01%
nginx-conf-parser bifrost nginx-config nginx nginx-configuration nginx-conf

bifrost's People

Contributors

clessli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bifrost's Issues

通常include下会放很多server的配置,如何方便解析和修改数据

大佬,你的这个解析方式很巧妙,非常适合处理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
看能解决不

文档

请问 , 这个怎么使用 , 有相关文档吗

nginx parse cannot parse lua script

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.