(key string, params []string)
| 116 | } |
| 117 | |
| 118 | func (s *Server) UpdateDirective(key string, params []string) { |
| 119 | if key == "" || len(params) == 0 { |
| 120 | return |
| 121 | } |
| 122 | if key == "listen" { |
| 123 | defaultServer := false |
| 124 | paramLen := len(params) |
| 125 | if paramLen > 0 && params[paramLen-1] == "default_server" { |
| 126 | params = params[:paramLen-1] |
| 127 | defaultServer = true |
| 128 | } |
| 129 | s.UpdateListen(params[0], defaultServer, params[1:]...) |
| 130 | return |
| 131 | } |
| 132 | |
| 133 | directives := s.Directives |
| 134 | index := -1 |
| 135 | for i, dir := range directives { |
| 136 | if dir.GetName() == key { |
| 137 | if IsRepeatKey(key) { |
| 138 | oldParams := dir.GetParameters() |
| 139 | if !(len(oldParams) > 0 && oldParams[0] == params[0]) { |
| 140 | continue |
| 141 | } |
| 142 | } |
| 143 | index = i |
| 144 | break |
| 145 | } |
| 146 | } |
| 147 | newDirective := &Directive{ |
| 148 | Name: key, |
| 149 | Parameters: params, |
| 150 | } |
| 151 | if index > -1 { |
| 152 | directives[index] = newDirective |
| 153 | } else { |
| 154 | directives = append(directives, newDirective) |
| 155 | } |
| 156 | s.Directives = directives |
| 157 | } |
| 158 | |
| 159 | func (s *Server) RemoveDirective(key string, params []string) { |
| 160 | directives := s.Directives |
no test coverage detected