1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package nginx
- import (
- "github.com/emirpasic/gods/queues/linkedlistqueue"
- "strings"
- )
- type CommentQueue struct {
- *linkedlistqueue.Queue
- }
- type NgxConfig struct {
- FileName string `json:"file_name"`
- Upstreams []NgxUpstream `json:"upstreams"`
- Servers []NgxServer `json:"ngx_server"`
- commentQueue *CommentQueue
- }
- type NgxServer struct {
- ServerName string `json:"server_name"`
- Directives NgxDirectives `json:"directives"`
- Locations []NgxLocation `json:"locations"`
- Comments string `json:"comments"`
- commentQueue *CommentQueue
- }
- type NgxUpstream struct {
- Name string `json:"name"`
- Directives NgxDirectives `json:"directives"`
- Comments string `json:"comments"`
- }
- type NgxDirective struct {
- Directive string `json:"directive"`
- Params string `json:"params"`
- Comments string `json:"comments"`
- }
- type NgxDirectives map[string][]NgxDirective
- type NgxLocation struct {
- Path string `json:"path"`
- Content string `json:"content"`
- Comments string `json:"comments"`
- }
- func (c *CommentQueue) DequeueAllComments() (comments string) {
- for !c.Empty() {
- comment, ok := c.Dequeue()
- if ok {
- comments += strings.TrimSpace(comment.(string)) + "\n"
- }
- }
- return
- }
- func (d *NgxDirective) Orig() string {
- return d.Directive + " " + d.Params
- }
- func (d *NgxDirective) TrimParams() {
- d.Params = strings.TrimRight(strings.TrimSpace(d.Params), ";")
- return
- }
- func NewNgxServer() *NgxServer {
- return &NgxServer{commentQueue: &CommentQueue{linkedlistqueue.New()}}
- }
- func NewNgxConfig(filename string) *NgxConfig {
- return &NgxConfig{FileName: filename, commentQueue: &CommentQueue{linkedlistqueue.New()}}
- }
|