1
0

ngx_conf_parse_test.go 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package test
  2. import (
  3. "fmt"
  4. "github.com/0xJacky/Nginx-UI/server/pkg/nginx"
  5. "testing"
  6. )
  7. func TestNgxConfParse(t *testing.T) {
  8. c, err := nginx.ParseNgxConfig("nextcloud_ngx.conf")
  9. if err != nil {
  10. t.Fatal(err)
  11. }
  12. fmt.Println(c.FileName)
  13. // directive in root
  14. fmt.Println("Upstream")
  15. for _, u := range c.Upstreams {
  16. fmt.Println("upstream name", u.Name)
  17. fmt.Printf("comments\n%v", u.Comments)
  18. for _, d := range u.Directives {
  19. fmt.Println("u.Directives.d", d)
  20. }
  21. }
  22. fmt.Println("==========================")
  23. fmt.Println("Servers")
  24. for _, s := range c.Servers {
  25. fmt.Printf("comments\n%v", s.Comments)
  26. for _, d := range s.Directives {
  27. fmt.Println(d)
  28. }
  29. // locations
  30. for _, location := range s.Locations {
  31. fmt.Printf("comments\n%v", location.Comments)
  32. fmt.Println("path", location.Path)
  33. fmt.Println("content", location.Content)
  34. fmt.Println("==========================")
  35. }
  36. }
  37. }