enhance(wip): error handle

This commit is contained in:
Jacky 2025-01-24 16:37:45 +08:00
parent 3f95ae5d90
commit 650196d06a
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
93 changed files with 5228 additions and 3738 deletions

7
cmd/errdef/generate.go Normal file
View file

@ -0,0 +1,7 @@
package main
import "github.com/uozi-tech/cosy/errdef"
func main() {
errdef.Generate()
}

View file

@ -2,7 +2,7 @@ package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"strings"
@ -15,10 +15,14 @@ type Directive struct {
}
func main() {
if len(os.Args) < 2 {
log.Println("Usage: go run . <output_file>")
}
outputPath := os.Args[1]
// Fetch page content
resp, err := http.Get("https://nginx.org/en/docs/dirindex.html")
if err != nil {
fmt.Println("Error fetching page:", err)
log.Println("[Error] fetching page:", err)
return
}
defer resp.Body.Close()
@ -26,7 +30,7 @@ func main() {
// Parse HTML
doc, err := html.Parse(resp.Body)
if err != nil {
fmt.Println("Error parsing HTML:", err)
log.Println("[Error] parsing HTML:", err)
return
}
@ -99,15 +103,15 @@ func main() {
// Write results to JSON file
jsonData, err := json.MarshalIndent(directives, "", " ")
if err != nil {
fmt.Println("Error marshaling JSON:", err)
log.Println("[Error] marshaling JSON:", err)
return
}
err = os.WriteFile("../../internal/nginx/nginx_directives.json", jsonData, 0644)
err = os.WriteFile(outputPath, jsonData, 0644)
if err != nil {
fmt.Println("Error writing file:", err)
log.Println("[Error] writing file:", err)
return
}
fmt.Printf("Successfully parsed %d directives and saved to nginx_directives.json\n", len(directives))
log.Printf("[OK] Successfully parsed %d directives and saved to %s\n", len(directives), outputPath)
}