Created
July 8, 2024 21:55
-
-
Save rikatz/2928938c6d354366e7b30e8cffc69bf1 to your computer and use it in GitHub Desktop.
nginx-go-crossplane parser for Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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