format_code.go 496 B

123456789101112131415161718192021
  1. package nginx
  2. import (
  3. "github.com/tufanbarisyildirim/gonginx"
  4. "github.com/tufanbarisyildirim/gonginx/parser"
  5. )
  6. func (c *NgxConfig) FmtCode() (fmtContent string) {
  7. fmtContent = gonginx.DumpConfig(c.c, gonginx.IndentedStyle)
  8. return
  9. }
  10. func FmtCode(content string) (fmtContent string, err error) {
  11. p := parser.NewStringParser(content, parser.WithSkipValidDirectivesErr())
  12. c, err := p.Parse()
  13. if err != nil {
  14. return
  15. }
  16. fmtContent = gonginx.DumpConfig(c, gonginx.IndentedStyle)
  17. return
  18. }