1
0

type.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package nginx
  2. import (
  3. "github.com/tufanbarisyildirim/gonginx"
  4. "strings"
  5. )
  6. type NgxConfig struct {
  7. FileName string `json:"file_name"`
  8. Upstreams []*NgxUpstream `json:"upstreams"`
  9. Servers []*NgxServer `json:"servers"`
  10. Custom string `json:"custom"`
  11. c *gonginx.Config
  12. }
  13. type NgxServer struct {
  14. Directives []*NgxDirective `json:"directives"`
  15. Locations []*NgxLocation `json:"locations"`
  16. Comments string `json:"comments"`
  17. }
  18. type NgxUpstream struct {
  19. Name string `json:"name"`
  20. Directives []*NgxDirective `json:"directives"`
  21. Comments string `json:"comments"`
  22. }
  23. type NgxDirective struct {
  24. Directive string `json:"directive"`
  25. Params string `json:"params"`
  26. Comments string `json:"comments"`
  27. }
  28. type NgxLocation struct {
  29. Path string `json:"path"`
  30. Content string `json:"content"`
  31. Comments string `json:"comments"`
  32. }
  33. func (d *NgxDirective) Orig() string {
  34. return d.Directive + " " + d.Params
  35. }
  36. func (d *NgxDirective) TrimParams() {
  37. d.Params = strings.TrimRight(strings.TrimSpace(d.Params), ";")
  38. return
  39. }
  40. func NewNgxServer() *NgxServer {
  41. return &NgxServer{
  42. Locations: make([]*NgxLocation, 0),
  43. Directives: make([]*NgxDirective, 0),
  44. }
  45. }
  46. func NewNgxConfig(filename string) *NgxConfig {
  47. return &NgxConfig{
  48. FileName: filename,
  49. Upstreams: make([]*NgxUpstream, 0),
  50. }
  51. }