http {
lua_package_path "/usr/local/nginx/test/lib/?.lua;;";
lua_shared_dict tracing_buffer 100m;
init_by_lua_block {
require "resty.core"
collectgarbage("collect")
}
server {
listen 80;
# some route rules ....
}
}
p, err := parser.NewParser("/Users/caiweicheng/Downloads/conf/nginx.conf")
if err != nil {
return err
}
return p.Parse()
panic: unexpected token BlockEnd (}) on line 27, column 5
goroutine 1 [running]:
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseStatement(0x14000132000, 0x3, 0x14000124150)
/Users/username/go/pkg/mod/github.com/tufanbarisyildirim/[email protected]/parser/parser.go:227 +0xaac
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseBlock(0x14000132000, 0x2)
/Users/username/go/pkg/mod/github.com/tufanbarisyildirim/[email protected]/parser/parser.go:165 +0xc4
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseStatement(0x14000132000, 0x5, 0x14000124138)
/Users/username/go/pkg/mod/github.com/tufanbarisyildirim/[email protected]/parser/parser.go:220 +0x6c0
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseBlock(0x14000132000, 0x2)
/Users/username/go/pkg/mod/github.com/tufanbarisyildirim/[email protected]/parser/parser.go:165 +0xc4
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseStatement(0x14000132000, 0x5, 0x140001240e0)
/Users/username/go/pkg/mod/github.com/tufanbarisyildirim/[email protected]/parser/parser.go:220 +0x6c0
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseBlock(0x14000132000, 0x2c)
/Users/username/go/pkg/mod/github.com/tufanbarisyildirim/[email protected]/parser/parser.go:165 +0xc4
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).Parse(...)
/Users/username/go/pkg/mod/github.com/tufanbarisyildirim/[email protected]/parser/parser.go:147
main.parseNginx(0x14000102058, 0x14000102000)
/Users/username/go-project/awesomeProject/nginxparse/main.go:17 +0x74
main.main()
I found out that this error is due to the fact that each line of the lua block does not need to end with a semicolon. But when NewParser
judges the end of the block, it must end with a semicolon.
At least parse nginx config not painc.
I have two thoughts: