mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
enhance: update gonginx and cosy to latest version
This commit is contained in:
parent
af9395ad69
commit
85da74b3f0
39 changed files with 799 additions and 662 deletions
|
@ -17,8 +17,7 @@ func buildComments(orig string, indent int) (content string) {
|
|||
return
|
||||
}
|
||||
|
||||
func (c *NgxConfig) BuildConfig() (content string) {
|
||||
|
||||
func (c *NgxConfig) BuildConfig() (content string, err error) {
|
||||
// Custom
|
||||
if c.Custom != "" {
|
||||
content += c.Custom
|
||||
|
@ -84,7 +83,11 @@ func (c *NgxConfig) BuildConfig() (content string) {
|
|||
content += fmt.Sprintf("%sserver {\n%s}\n\n", comments, server)
|
||||
}
|
||||
p := parser.NewStringParser(content)
|
||||
config := p.Parse()
|
||||
config, err := p.Parse()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
content = gonginx.DumpConfig(config, gonginx.IndentedStyle)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -10,9 +10,12 @@ func (c *NgxConfig) FmtCode() (fmtContent string) {
|
|||
return
|
||||
}
|
||||
|
||||
func FmtCode(content string) (fmtContent string) {
|
||||
func FmtCode(content string) (fmtContent string, err error) {
|
||||
p := parser.NewStringParser(content)
|
||||
c := p.Parse()
|
||||
c, err := p.Parse()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmtContent = gonginx.DumpConfig(c, gonginx.IndentedStyle)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -127,8 +127,9 @@ func buildComment(c []string) string {
|
|||
return strings.ReplaceAll(strings.Join(c, "\n"), "#", "")
|
||||
}
|
||||
|
||||
func parse(block gonginx.IBlock, ngxConfig *NgxConfig) {
|
||||
func parse(block gonginx.IBlock, ngxConfig *NgxConfig) (err error) {
|
||||
if block == nil {
|
||||
err = errors.New("block is nil")
|
||||
return
|
||||
}
|
||||
for _, v := range block.GetDirectives() {
|
||||
|
@ -152,15 +153,23 @@ func parse(block gonginx.IBlock, ngxConfig *NgxConfig) {
|
|||
ngxConfig.parseCustom(v)
|
||||
}
|
||||
}
|
||||
ngxConfig.Custom = FmtCode(ngxConfig.Custom)
|
||||
custom, err := FmtCode(ngxConfig.Custom)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ngxConfig.Custom = custom
|
||||
return
|
||||
}
|
||||
|
||||
func ParseNgxConfigByContent(content string) (ngxConfig *NgxConfig) {
|
||||
func ParseNgxConfigByContent(content string) (ngxConfig *NgxConfig, err error) {
|
||||
p := parser.NewStringParser(content)
|
||||
c := p.Parse()
|
||||
c, err := p.Parse()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ngxConfig = NewNgxConfig("")
|
||||
ngxConfig.c = c
|
||||
parse(c.Block, ngxConfig)
|
||||
err = parse(c.Block, ngxConfig)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -169,9 +178,12 @@ func ParseNgxConfig(filename string) (ngxConfig *NgxConfig, err error) {
|
|||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error ParseNgxConfig")
|
||||
}
|
||||
c := p.Parse()
|
||||
c, err := p.Parse()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ngxConfig = NewNgxConfig(filename)
|
||||
ngxConfig.c = c
|
||||
parse(c.Block, ngxConfig)
|
||||
err = parse(c.Block, ngxConfig)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue