|
@@ -1,64 +1,64 @@
|
|
package nginx
|
|
package nginx
|
|
|
|
|
|
import (
|
|
import (
|
|
- "github.com/tufanbarisyildirim/gonginx"
|
|
|
|
- "path"
|
|
|
|
- "strings"
|
|
|
|
|
|
+ "github.com/tufanbarisyildirim/gonginx"
|
|
|
|
+ "path"
|
|
|
|
+ "strings"
|
|
)
|
|
)
|
|
|
|
|
|
type NgxConfig struct {
|
|
type NgxConfig struct {
|
|
- FileName string `json:"file_name"`
|
|
|
|
- Name string `json:"name"`
|
|
|
|
- Upstreams []*NgxUpstream `json:"upstreams"`
|
|
|
|
- Servers []*NgxServer `json:"servers"`
|
|
|
|
- Custom string `json:"custom"`
|
|
|
|
- c *gonginx.Config
|
|
|
|
|
|
+ FileName string `json:"file_name"`
|
|
|
|
+ Name string `json:"name"`
|
|
|
|
+ Upstreams []*NgxUpstream `json:"upstreams,omitempty"`
|
|
|
|
+ Servers []*NgxServer `json:"servers,omitempty"`
|
|
|
|
+ Custom string `json:"custom"`
|
|
|
|
+ c *gonginx.Config
|
|
}
|
|
}
|
|
|
|
|
|
type NgxServer struct {
|
|
type NgxServer struct {
|
|
- Directives []*NgxDirective `json:"directives"`
|
|
|
|
- Locations []*NgxLocation `json:"locations"`
|
|
|
|
- Comments string `json:"comments"`
|
|
|
|
|
|
+ Directives []*NgxDirective `json:"directives,omitempty"`
|
|
|
|
+ Locations []*NgxLocation `json:"locations,omitempty"`
|
|
|
|
+ Comments string `json:"comments"`
|
|
}
|
|
}
|
|
|
|
|
|
type NgxUpstream struct {
|
|
type NgxUpstream struct {
|
|
- Name string `json:"name"`
|
|
|
|
- Directives []*NgxDirective `json:"directives"`
|
|
|
|
- Comments string `json:"comments"`
|
|
|
|
|
|
+ Name string `json:"name"`
|
|
|
|
+ Directives []*NgxDirective `json:"directives,omitempty"`
|
|
|
|
+ Comments string `json:"comments"`
|
|
}
|
|
}
|
|
|
|
|
|
type NgxDirective struct {
|
|
type NgxDirective struct {
|
|
- Directive string `json:"directive"`
|
|
|
|
- Params string `json:"params"`
|
|
|
|
- Comments string `json:"comments"`
|
|
|
|
|
|
+ Directive string `json:"directive"`
|
|
|
|
+ Params string `json:"params"`
|
|
|
|
+ Comments string `json:"comments"`
|
|
}
|
|
}
|
|
|
|
|
|
type NgxLocation struct {
|
|
type NgxLocation struct {
|
|
- Path string `json:"path"`
|
|
|
|
- Content string `json:"content"`
|
|
|
|
- Comments string `json:"comments"`
|
|
|
|
|
|
+ Path string `json:"path"`
|
|
|
|
+ Content string `json:"content"`
|
|
|
|
+ Comments string `json:"comments"`
|
|
}
|
|
}
|
|
|
|
|
|
func (d *NgxDirective) Orig() string {
|
|
func (d *NgxDirective) Orig() string {
|
|
- return d.Directive + " " + d.Params
|
|
|
|
|
|
+ return d.Directive + " " + d.Params
|
|
}
|
|
}
|
|
|
|
|
|
func (d *NgxDirective) TrimParams() {
|
|
func (d *NgxDirective) TrimParams() {
|
|
- d.Params = strings.TrimRight(strings.TrimSpace(d.Params), ";")
|
|
|
|
- return
|
|
|
|
|
|
+ d.Params = strings.TrimRight(strings.TrimSpace(d.Params), ";")
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
func NewNgxServer() *NgxServer {
|
|
func NewNgxServer() *NgxServer {
|
|
- return &NgxServer{
|
|
|
|
- Locations: make([]*NgxLocation, 0),
|
|
|
|
- Directives: make([]*NgxDirective, 0),
|
|
|
|
- }
|
|
|
|
|
|
+ return &NgxServer{
|
|
|
|
+ Locations: make([]*NgxLocation, 0),
|
|
|
|
+ Directives: make([]*NgxDirective, 0),
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func NewNgxConfig(filename string) *NgxConfig {
|
|
func NewNgxConfig(filename string) *NgxConfig {
|
|
- return &NgxConfig{
|
|
|
|
- FileName: filename,
|
|
|
|
- Upstreams: make([]*NgxUpstream, 0),
|
|
|
|
- Name: path.Base(filename),
|
|
|
|
- }
|
|
|
|
|
|
+ return &NgxConfig{
|
|
|
|
+ FileName: filename,
|
|
|
|
+ Upstreams: make([]*NgxUpstream, 0),
|
|
|
|
+ Name: path.Base(filename),
|
|
|
|
+ }
|
|
}
|
|
}
|