format_code.go 574 B

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