gracefull shutdown for unresolvable errors

This commit is contained in:
2025-03-07 21:40:53 +07:00
parent 2fd8b20b77
commit e6f21d1bb2
19 changed files with 181 additions and 133 deletions

View File

@@ -1,32 +1,36 @@
package utils
import (
"bufio"
"os"
"strings"
"bufio"
"log"
"os"
"strings"
)
func GetStructList(filePath string) ([]string) {
file, err := os.Open(filePath)
if err != nil {
panic(err)
}
defer file.Close()
var structNames []string
s := bufio.NewScanner(file)
for s.Scan() {
line := s.Text()
if strings.Contains(line, "type ") && strings.Contains(line, " struct") {
start := strings.Index(line, "type ") + 5
end := strings.Index(line, " struct")
name := strings.TrimSpace(line[start:end])
if name != "" {
structNames = append(structNames, name)
}
}
}
if err := s.Err(); err != nil {
panic(err)
}
return structNames
}
func GetStructList(filePath string) []string {
file, err := os.Open(filePath)
defer file.Close()
if err != nil {
log.Fatalf("Failed to open a file: %s", err)
}
var structNames []string
s := bufio.NewScanner(file)
for s.Scan() {
line := s.Text()
if strings.Contains(line, "type ") && strings.Contains(line, " struct") {
start := strings.Index(line, "type ") + 5
end := strings.Index(line, " struct")
name := strings.TrimSpace(line[start:end])
if name != "" {
structNames = append(structNames, name)
}
}
}
if s.Err() != nil {
log.Fatalf("")
}
return structNames
}