Skip to content
프로젝트

소개

Nginx configuration parser helps you to parse, edit, regenerate your nginx config in your go applications

개발 도구

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Report Card Actions Status

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 into tokens and parser 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

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.

Behavior Notes

  • Parser APIs return errors for malformed input; malformed configs should not crash your process.
  • Include parsing (parser.WithIncludeParsing()) deduplicates includes by canonical path and skips cyclic include branches by default.
  • Use parser.WithIncludeCycleErr() to fail fast on include-cycle detection.
  • dumper.NoIndentSortedStyle / sorted dump options no longer mutate directive order in the in-memory AST.
  • Parent semantics:
    • root-level leaf directives have nil parent,
    • nested directives point to their enclosing directive wrapper (http, server, location, etc.).
  • Upstream lookup:
    • FindUpstreams() is permissive and skips unexpected upstream directive types.
    • FindUpstreamsStrict() returns a typed error when a matched upstream is not *config.Upstream.
  • Lua comment style policy:
    • existing -- comments stay --,
    • nginx-style # comments are preserved where originally used and safe,
    • formatter failures fall back to original Lua code.

License

MIT License

관련 프로젝트 살펴보기

불러오는 중…