Skip to content

Instantly share code, notes, and snippets.

@rikatz
Created July 8, 2024 21:55
Show Gist options
  • Save rikatz/2928938c6d354366e7b30e8cffc69bf1 to your computer and use it in GitHub Desktop.
Save rikatz/2928938c6d354366e7b30e8cffc69bf1 to your computer and use it in GitHub Desktop.
nginx-go-crossplane parser for Lua
package main
import (
"encoding/json"
"fmt"
crossplane "github.com/nginxinc/nginx-go-crossplane"
)
func main() {
path := "nginx-nok.conf"
lua := crossplane.Lua{}
payload, err := crossplane.Parse(path, &crossplane.ParseOptions{
ErrorOnUnknownDirectives: true,
StopParsingOnError: true,
IgnoreDirectives: []string{"more_clear_headers", "lua_add_variable"},
DirectiveSources: []crossplane.MatchFunc{crossplane.DefaultDirectivesMatchFunc, crossplane.LuaDirectivesMatchFn},
LexOptions: crossplane.LexOptions{
Lexers: []crossplane.RegisterLexer{lua.RegisterLexer()},
},
})
if err != nil {
panic(err)
}
b, err := json.Marshal(payload)
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment