mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 02:45:49 +02:00
fix(nginx-config): parse custom config error #699
This commit is contained in:
parent
502b656bc5
commit
92dc61ecb4
2 changed files with 8 additions and 3 deletions
|
@ -3,6 +3,7 @@ package nginx
|
||||||
import (
|
import (
|
||||||
"github.com/tufanbarisyildirim/gonginx/dumper"
|
"github.com/tufanbarisyildirim/gonginx/dumper"
|
||||||
"github.com/tufanbarisyildirim/gonginx/parser"
|
"github.com/tufanbarisyildirim/gonginx/parser"
|
||||||
|
"github.com/uozi-tech/cosy/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *NgxConfig) FmtCode() (fmtContent string) {
|
func (c *NgxConfig) FmtCode() (fmtContent string) {
|
||||||
|
@ -11,6 +12,7 @@ func (c *NgxConfig) FmtCode() (fmtContent string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func FmtCode(content string) (fmtContent string, err error) {
|
func FmtCode(content string) (fmtContent string, err error) {
|
||||||
|
logger.Debugf("content: %s", content)
|
||||||
p := parser.NewStringParser(content, parser.WithSkipValidDirectivesErr())
|
p := parser.NewStringParser(content, parser.WithSkipValidDirectivesErr())
|
||||||
c, err := p.Parse()
|
c, err := p.Parse()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package nginx
|
package nginx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/tufanbarisyildirim/gonginx/config"
|
"github.com/tufanbarisyildirim/gonginx/config"
|
||||||
"github.com/tufanbarisyildirim/gonginx/parser"
|
"github.com/tufanbarisyildirim/gonginx/parser"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -135,9 +136,11 @@ func (u *NgxUpstream) parseUpstream(directive config.IDirective) {
|
||||||
|
|
||||||
func (c *NgxConfig) parseCustom(directive config.IDirective) {
|
func (c *NgxConfig) parseCustom(directive config.IDirective) {
|
||||||
if directive.GetBlock() == nil {
|
if directive.GetBlock() == nil {
|
||||||
|
// fix #699
|
||||||
|
c.Custom += ";\n"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Custom += "{\n"
|
c.Custom += "\n{\n"
|
||||||
for _, v := range directive.GetBlock().GetDirectives() {
|
for _, v := range directive.GetBlock().GetDirectives() {
|
||||||
var params []string
|
var params []string
|
||||||
for _, param := range v.GetParameters() {
|
for _, param := range v.GetParameters() {
|
||||||
|
@ -183,7 +186,7 @@ func parse(block config.IBlock, ngxConfig *NgxConfig) (err error) {
|
||||||
params = append(params, param.Value)
|
params = append(params, param.Value)
|
||||||
}
|
}
|
||||||
ngxConfig.Custom += strings.Join(v.GetComment(), "\n") + "\n" +
|
ngxConfig.Custom += strings.Join(v.GetComment(), "\n") + "\n" +
|
||||||
v.GetName() + " " + strings.Join(params, " ") + "\n"
|
v.GetName() + " " + strings.Join(params, " ")
|
||||||
ngxConfig.parseCustom(v)
|
ngxConfig.parseCustom(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue