mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-13 03:15:48 +02:00
bug fix and translated login error msg
This commit is contained in:
parent
f11fd19288
commit
b2e837f4b1
35 changed files with 324 additions and 301 deletions
49
server/pkg/nginx/format_code.go
Normal file
49
server/pkg/nginx/format_code.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package nginx
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"github.com/emirpasic/gods/stacks/linkedliststack"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func fmtCode(content string) (fmtContent string) {
|
||||
fmtContent = fmtCodeWithIndent(content, 0)
|
||||
return
|
||||
}
|
||||
|
||||
func fmtCodeWithIndent(content string, indent int) (fmtContent string) {
|
||||
/*
|
||||
Format content
|
||||
1. TrimSpace for each line
|
||||
2. use stack to count how many \t should add
|
||||
*/
|
||||
stack := linkedliststack.New()
|
||||
|
||||
scanner := bufio.NewScanner(strings.NewReader(content))
|
||||
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
text = strings.TrimSpace(text)
|
||||
|
||||
before := stack.Size()
|
||||
|
||||
for _, char := range text {
|
||||
matchParentheses(stack, char)
|
||||
}
|
||||
|
||||
after := stack.Size()
|
||||
|
||||
fmtContent += strings.Repeat("\t", indent)
|
||||
|
||||
if before == after {
|
||||
fmtContent += strings.Repeat("\t", stack.Size()) + text + "\n"
|
||||
} else {
|
||||
fmtContent += text + "\n"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fmtContent = strings.Trim(fmtContent, "\n")
|
||||
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue