MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / UpdateDirective

Method UpdateDirective

agent/utils/nginx/components/server.go:118–157  ·  view source on GitHub ↗
(key string, params []string)

Source from the content-addressed store, hash-verified

116}
117
118func (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
159func (s *Server) RemoveDirective(key string, params []string) {
160 directives := s.Directives

Callers 2

UpdateServerNameMethod · 0.95
UpdateRootMethod · 0.95

Calls 4

UpdateListenMethod · 0.95
IsRepeatKeyFunction · 0.85
GetNameMethod · 0.65
GetParametersMethod · 0.65

Tested by

no test coverage detected