Awesome
<p align="center"><img src="./gopher.png" width="360"></p> <p align="center"> <a href="https://goreportcard.com/badge/github.com/tufanbarisyildirim/gonginx"><img src="https://goreportcard.com/badge/github.com/tufanbarisyildirim/gonginx" alt="Report Card" /></a> <a href="https://github.com/tufanbarisyildirim/gonging/actions"><img src="https://github.com/tufanbarisyildirim/gonginx/workflows/Go/badge.svg" alt="Actions Status" /></a> </p>Gonginx
TBH, I would like to rewrite the parser next time I need it again :)) but it still does its job.
Gonginx is an Nginx configuration parser helps you to parse, edit, regenerate your nginx config files in your go applications. It makes managing your balancer configurations easier.
Basic grammar of an nginx config file
%token Keyword Variable BlockStart BlockEnd Semicolon Regex
%%
config : /* empty */
| config directives
;
block : BlockStart directives BlockEnd
;
directives : directives directive
;
directive : Keyword [parameters] (semicolon|block)
;
parameters : parameters keyword
;
keyword : Keyword
| Variable
| Regex
;
API
Core Components
-
Parser
Parser is the main package that analyzes and turns nginx structred files into objects. It basically has 3 libraries,lexer
explodes it intotoken
s andparser
turns tokens into config objects which are in their own package, -
Config
Config package is representation of any context, directive or their parameters in golang. So basically they are models and also AST -
Dumper
Dumper is the package that holds styling configuration only.
Examples
- Formatting
- Adding a Server to upstream block
- add-custom-directive
- dump-nginx-config
- update-directive
- update-server-listen-port
Examples and Library Reference
TODO
- associate comments with config objects to print them on config generation and make it configurable with
dumper.Style
- move any context wrapper into their own file (remove from parser)
- Parse included files recusively, keep relative path on load, save all in a related structure and make that optional in dumper.Style
- Implement specific searches, like finding servers by server_name (domain) or any upstream by target etc.
- add more examples
- link the parent directive to any directive for easier manipulation
Limitations
There is no known limitations yet. PRs are more than welcome if you want to implement a specific directive / block, please read Contributing before your first PR.