@@ -157,136 +157,141 @@ func (b *ServerOptionIDValue) String() string {
157
157
return fmt .Sprintf ("%s(%s) %s" , b .Name , b .ID , b .Value )
158
158
}
159
159
160
- func getServerOptions () []ServerOption {
161
- return []ServerOption {
162
- & ServerOptionWord {Name : "agent-check" },
163
- & ServerOptionWord {Name : "allow-0rtt" },
164
- & ServerOptionWord {Name : "backup" },
165
- & ServerOptionWord {Name : "check" },
166
- & ServerOptionWord {Name : "check-send-proxy" },
167
- & ServerOptionWord {Name : "check-ssl" },
168
- & ServerOptionWord {Name : "check-via-socks4" },
169
- & ServerOptionWord {Name : "disabled" },
170
- & ServerOptionWord {Name : "enabled" },
171
- & ServerOptionWord {Name : "force-sslv3" },
172
- & ServerOptionWord {Name : "force-tlsv10" },
173
- & ServerOptionWord {Name : "force-tlsv11" },
174
- & ServerOptionWord {Name : "force-tlsv12" },
175
- & ServerOptionWord {Name : "force-tlsv13" },
176
- & ServerOptionWord {Name : "no-agent-check" },
177
- & ServerOptionWord {Name : "no-backup" },
178
- & ServerOptionWord {Name : "no-check" },
179
- & ServerOptionWord {Name : "no-check-ssl" },
180
- & ServerOptionWord {Name : "no-send-proxy" },
181
- & ServerOptionWord {Name : "no-send-proxy-v2" },
182
- & ServerOptionWord {Name : "no-send-proxy-v2-ssl" },
183
- & ServerOptionWord {Name : "no-send-proxy-v2-ssl-cn" },
184
- & ServerOptionWord {Name : "no-ssl" },
185
- & ServerOptionWord {Name : "no-ssl-reuse" },
186
- & ServerOptionWord {Name : "no-sslv3" },
187
- & ServerOptionWord {Name : "no-tls-tickets" },
188
- & ServerOptionWord {Name : "no-tlsv10" },
189
- & ServerOptionWord {Name : "no-tlsv11" },
190
- & ServerOptionWord {Name : "no-tlsv12" },
191
- & ServerOptionWord {Name : "no-tlsv13" },
192
- & ServerOptionWord {Name : "no-verifyhost" },
193
- & ServerOptionWord {Name : "no-tfo" },
194
- & ServerOptionWord {Name : "non-stick" },
195
- & ServerOptionWord {Name : "send-proxy" },
196
- & ServerOptionWord {Name : "send-proxy-v2" },
197
- & ServerOptionWord {Name : "send-proxy-v2-ssl" },
198
- & ServerOptionWord {Name : "send-proxy-v2-ssl-cn" },
199
- & ServerOptionWord {Name : "ssl" },
200
- & ServerOptionWord {Name : "ssl-reuse" },
201
- & ServerOptionWord {Name : "stick" },
202
- & ServerOptionWord {Name : "tfo" },
203
- & ServerOptionWord {Name : "tls-tickets" },
204
- & ServerOptionValue {Name : "addr" },
205
- & ServerOptionValue {Name : "agent-send" },
206
- & ServerOptionValue {Name : "agent-inter" },
207
- & ServerOptionValue {Name : "agent-addr" },
208
- & ServerOptionValue {Name : "agent-port" },
209
- & ServerOptionValue {Name : "alpn" },
210
- & ServerOptionValue {Name : "ca-file" },
211
- & ServerOptionValue {Name : "check-alpn" },
212
- & ServerOptionValue {Name : "check-proto" },
213
- & ServerOptionValue {Name : "check-sni" },
214
- & ServerOptionValue {Name : "ciphers" },
215
- & ServerOptionValue {Name : "ciphersuites" },
216
- & ServerOptionValue {Name : "client-sigalgs" },
217
- & ServerOptionValue {Name : "cookie" },
218
- & ServerOptionValue {Name : "crl-file" },
219
- & ServerOptionValue {Name : "crt" },
220
- & ServerOptionValue {Name : "curves" },
221
- & ServerOptionValue {Name : "error-limit" },
222
- & ServerOptionValue {Name : "fall" },
223
- & ServerOptionValue {Name : "id" },
224
- & ServerOptionValue {Name : "init-addr" },
225
- & ServerOptionValue {Name : "inter" },
226
- & ServerOptionValue {Name : "fastinter" },
227
- & ServerOptionValue {Name : "downinter" },
228
- & ServerOptionValue {Name : "log-proto" },
229
- & ServerOptionValue {Name : "maxconn" },
230
- & ServerOptionValue {Name : "maxqueue" },
231
- & ServerOptionValue {Name : "max-reuse" },
232
- & ServerOptionValue {Name : "minconn" },
233
- & ServerOptionValue {Name : "namespace" },
234
- & ServerOptionValue {Name : "npn" },
235
- & ServerOptionValue {Name : "observe" },
236
- & ServerOptionValue {Name : "on-error" },
237
- & ServerOptionValue {Name : "on-marked-down" },
238
- & ServerOptionValue {Name : "on-marked-up" },
239
- & ServerOptionValue {Name : "pool-max-conn" },
240
- & ServerOptionValue {Name : "pool-purge-delay" },
241
- & ServerOptionValue {Name : "port" },
242
- & ServerOptionValue {Name : "proto" },
243
- & ServerOptionValue {Name : "redir" },
244
- & ServerOptionValue {Name : "rise" },
245
- & ServerOptionValue {Name : "resolve-opts" },
246
- & ServerOptionValue {Name : "resolve-prefer" },
247
- & ServerOptionValue {Name : "resolve-net" },
248
- & ServerOptionValue {Name : "resolvers" },
249
- & ServerOptionValue {Name : "proxy-v2-options" },
250
- & ServerOptionValue {Name : "shard" },
251
- & ServerOptionValue {Name : "sigalgs" },
252
- & ServerOptionValue {Name : "slowstart" },
253
- & ServerOptionValue {Name : "sni" },
254
- & ServerOptionValue {Name : "source" },
255
- & ServerOptionValue {Name : "usesrc" },
256
- & ServerOptionValue {Name : "interface" },
257
- & ServerOptionValue {Name : "ssl-max-ver" },
258
- & ServerOptionValue {Name : "ssl-min-ver" },
259
- & ServerOptionValue {Name : "socks4" },
260
- & ServerOptionValue {Name : "tcp-ut" },
261
- & ServerOptionValue {Name : "track" },
262
- & ServerOptionValue {Name : "verify" },
263
- & ServerOptionValue {Name : "verifyhost" },
264
- & ServerOptionValue {Name : "weight" },
265
- & ServerOptionValue {Name : "pool-low-conn" },
266
- & ServerOptionValue {Name : "ws" },
267
- & ServerOptionValue {Name : "log-bufsize" },
268
- & ServerOptionValue {Name : "guid" },
269
- & ServerOptionIDValue {Name : "set-proxy-v2-tlv-fmt" },
270
- & ServerOptionValue {Name : "pool-conn-name" },
271
- & ServerOptionValue {Name : "hash-key" },
160
+ var serverOptionFactoryMethods = map [string ]func () ServerOption { //nolint:gochecknoglobals
161
+ "agent-check" : func () ServerOption { return & ServerOptionWord {Name : "agent-check" } },
162
+ "allow-0rtt" : func () ServerOption { return & ServerOptionWord {Name : "allow-0rtt" } },
163
+ "backup" : func () ServerOption { return & ServerOptionWord {Name : "backup" } },
164
+ "check" : func () ServerOption { return & ServerOptionWord {Name : "check" } },
165
+ "check-send-proxy" : func () ServerOption { return & ServerOptionWord {Name : "check-send-proxy" } },
166
+ "check-ssl" : func () ServerOption { return & ServerOptionWord {Name : "check-ssl" } },
167
+ "check-via-socks4" : func () ServerOption { return & ServerOptionWord {Name : "check-via-socks4" } },
168
+ "disabled" : func () ServerOption { return & ServerOptionWord {Name : "disabled" } },
169
+ "enabled" : func () ServerOption { return & ServerOptionWord {Name : "enabled" } },
170
+ "force-sslv3" : func () ServerOption { return & ServerOptionWord {Name : "force-sslv3" } },
171
+ "force-tlsv10" : func () ServerOption { return & ServerOptionWord {Name : "force-tlsv10" } },
172
+ "force-tlsv11" : func () ServerOption { return & ServerOptionWord {Name : "force-tlsv11" } },
173
+ "force-tlsv12" : func () ServerOption { return & ServerOptionWord {Name : "force-tlsv12" } },
174
+ "force-tlsv13" : func () ServerOption { return & ServerOptionWord {Name : "force-tlsv13" } },
175
+ "no-agent-check" : func () ServerOption { return & ServerOptionWord {Name : "no-agent-check" } },
176
+ "no-backup" : func () ServerOption { return & ServerOptionWord {Name : "no-backup" } },
177
+ "no-check" : func () ServerOption { return & ServerOptionWord {Name : "no-check" } },
178
+ "no-check-ssl" : func () ServerOption { return & ServerOptionWord {Name : "no-check-ssl" } },
179
+ "no-send-proxy" : func () ServerOption { return & ServerOptionWord {Name : "no-send-proxy" } },
180
+ "no-send-proxy-v2" : func () ServerOption { return & ServerOptionWord {Name : "no-send-proxy-v2" } },
181
+ "no-send-proxy-v2-ssl" : func () ServerOption { return & ServerOptionWord {Name : "no-send-proxy-v2-ssl" } },
182
+ "no-send-proxy-v2-ssl-cn" : func () ServerOption { return & ServerOptionWord {Name : "no-send-proxy-v2-ssl-cn" } },
183
+ "no-ssl" : func () ServerOption { return & ServerOptionWord {Name : "no-ssl" } },
184
+ "no-ssl-reuse" : func () ServerOption { return & ServerOptionWord {Name : "no-ssl-reuse" } },
185
+ "no-sslv3" : func () ServerOption { return & ServerOptionWord {Name : "no-sslv3" } },
186
+ "no-tls-tickets" : func () ServerOption { return & ServerOptionWord {Name : "no-tls-tickets" } },
187
+ "no-tlsv10" : func () ServerOption { return & ServerOptionWord {Name : "no-tlsv10" } },
188
+ "no-tlsv11" : func () ServerOption { return & ServerOptionWord {Name : "no-tlsv11" } },
189
+ "no-tlsv12" : func () ServerOption { return & ServerOptionWord {Name : "no-tlsv12" } },
190
+ "no-tlsv13" : func () ServerOption { return & ServerOptionWord {Name : "no-tlsv13" } },
191
+ "no-verifyhost" : func () ServerOption { return & ServerOptionWord {Name : "no-verifyhost" } },
192
+ "no-tfo" : func () ServerOption { return & ServerOptionWord {Name : "no-tfo" } },
193
+ "non-stick" : func () ServerOption { return & ServerOptionWord {Name : "non-stick" } },
194
+ "send-proxy" : func () ServerOption { return & ServerOptionWord {Name : "send-proxy" } },
195
+ "send-proxy-v2" : func () ServerOption { return & ServerOptionWord {Name : "send-proxy-v2" } },
196
+ "send-proxy-v2-ssl" : func () ServerOption { return & ServerOptionWord {Name : "send-proxy-v2-ssl" } },
197
+ "send-proxy-v2-ssl-cn" : func () ServerOption { return & ServerOptionWord {Name : "send-proxy-v2-ssl-cn" } },
198
+ "ssl" : func () ServerOption { return & ServerOptionWord {Name : "ssl" } },
199
+ "ssl-reuse" : func () ServerOption { return & ServerOptionWord {Name : "ssl-reuse" } },
200
+ "stick" : func () ServerOption { return & ServerOptionWord {Name : "stick" } },
201
+ "tfo" : func () ServerOption { return & ServerOptionWord {Name : "tfo" } },
202
+ "tls-tickets" : func () ServerOption { return & ServerOptionWord {Name : "tls-tickets" } },
203
+ "addr" : func () ServerOption { return & ServerOptionValue {Name : "addr" } },
204
+ "agent-send" : func () ServerOption { return & ServerOptionValue {Name : "agent-send" } },
205
+ "agent-inter" : func () ServerOption { return & ServerOptionValue {Name : "agent-inter" } },
206
+ "agent-addr" : func () ServerOption { return & ServerOptionValue {Name : "agent-addr" } },
207
+ "agent-port" : func () ServerOption { return & ServerOptionValue {Name : "agent-port" } },
208
+ "alpn" : func () ServerOption { return & ServerOptionValue {Name : "alpn" } },
209
+ "ca-file" : func () ServerOption { return & ServerOptionValue {Name : "ca-file" } },
210
+ "check-alpn" : func () ServerOption { return & ServerOptionValue {Name : "check-alpn" } },
211
+ "check-proto" : func () ServerOption { return & ServerOptionValue {Name : "check-proto" } },
212
+ "check-sni" : func () ServerOption { return & ServerOptionValue {Name : "check-sni" } },
213
+ "ciphers" : func () ServerOption { return & ServerOptionValue {Name : "ciphers" } },
214
+ "ciphersuites" : func () ServerOption { return & ServerOptionValue {Name : "ciphersuites" } },
215
+ "client-sigalgs" : func () ServerOption { return & ServerOptionValue {Name : "client-sigalgs" } },
216
+ "cookie" : func () ServerOption { return & ServerOptionValue {Name : "cookie" } },
217
+ "crl-file" : func () ServerOption { return & ServerOptionValue {Name : "crl-file" } },
218
+ "crt" : func () ServerOption { return & ServerOptionValue {Name : "crt" } },
219
+ "curves" : func () ServerOption { return & ServerOptionValue {Name : "curves" } },
220
+ "error-limit" : func () ServerOption { return & ServerOptionValue {Name : "error-limit" } },
221
+ "fall" : func () ServerOption { return & ServerOptionValue {Name : "fall" } },
222
+ "id" : func () ServerOption { return & ServerOptionValue {Name : "id" } },
223
+ "init-addr" : func () ServerOption { return & ServerOptionValue {Name : "init-addr" } },
224
+ "inter" : func () ServerOption { return & ServerOptionValue {Name : "inter" } },
225
+ "fastinter" : func () ServerOption { return & ServerOptionValue {Name : "fastinter" } },
226
+ "downinter" : func () ServerOption { return & ServerOptionValue {Name : "downinter" } },
227
+ "log-proto" : func () ServerOption { return & ServerOptionValue {Name : "log-proto" } },
228
+ "maxconn" : func () ServerOption { return & ServerOptionValue {Name : "maxconn" } },
229
+ "maxqueue" : func () ServerOption { return & ServerOptionValue {Name : "maxqueue" } },
230
+ "max-reuse" : func () ServerOption { return & ServerOptionValue {Name : "max-reuse" } },
231
+ "minconn" : func () ServerOption { return & ServerOptionValue {Name : "minconn" } },
232
+ "namespace" : func () ServerOption { return & ServerOptionValue {Name : "namespace" } },
233
+ "npn" : func () ServerOption { return & ServerOptionValue {Name : "npn" } },
234
+ "observe" : func () ServerOption { return & ServerOptionValue {Name : "observe" } },
235
+ "on-error" : func () ServerOption { return & ServerOptionValue {Name : "on-error" } },
236
+ "on-marked-down" : func () ServerOption { return & ServerOptionValue {Name : "on-marked-down" } },
237
+ "on-marked-up" : func () ServerOption { return & ServerOptionValue {Name : "on-marked-up" } },
238
+ "pool-max-conn" : func () ServerOption { return & ServerOptionValue {Name : "pool-max-conn" } },
239
+ "pool-purge-delay" : func () ServerOption { return & ServerOptionValue {Name : "pool-purge-delay" } },
240
+ "port" : func () ServerOption { return & ServerOptionValue {Name : "port" } },
241
+ "proto" : func () ServerOption { return & ServerOptionValue {Name : "proto" } },
242
+ "redir" : func () ServerOption { return & ServerOptionValue {Name : "redir" } },
243
+ "rise" : func () ServerOption { return & ServerOptionValue {Name : "rise" } },
244
+ "resolve-opts" : func () ServerOption { return & ServerOptionValue {Name : "resolve-opts" } },
245
+ "resolve-prefer" : func () ServerOption { return & ServerOptionValue {Name : "resolve-prefer" } },
246
+ "resolve-net" : func () ServerOption { return & ServerOptionValue {Name : "resolve-net" } },
247
+ "resolvers" : func () ServerOption { return & ServerOptionValue {Name : "resolvers" } },
248
+ "proxy-v2-options" : func () ServerOption { return & ServerOptionValue {Name : "proxy-v2-options" } },
249
+ "shard" : func () ServerOption { return & ServerOptionValue {Name : "shard" } },
250
+ "sigalgs" : func () ServerOption { return & ServerOptionValue {Name : "sigalgs" } },
251
+ "slowstart" : func () ServerOption { return & ServerOptionValue {Name : "slowstart" } },
252
+ "sni" : func () ServerOption { return & ServerOptionValue {Name : "sni" } },
253
+ "source" : func () ServerOption { return & ServerOptionValue {Name : "source" } },
254
+ "usesrc" : func () ServerOption { return & ServerOptionValue {Name : "usesrc" } },
255
+ "interface" : func () ServerOption { return & ServerOptionValue {Name : "interface" } },
256
+ "ssl-max-ver" : func () ServerOption { return & ServerOptionValue {Name : "ssl-max-ver" } },
257
+ "ssl-min-ver" : func () ServerOption { return & ServerOptionValue {Name : "ssl-min-ver" } },
258
+ "socks4" : func () ServerOption { return & ServerOptionValue {Name : "socks4" } },
259
+ "tcp-ut" : func () ServerOption { return & ServerOptionValue {Name : "tcp-ut" } },
260
+ "track" : func () ServerOption { return & ServerOptionValue {Name : "track" } },
261
+ "verify" : func () ServerOption { return & ServerOptionValue {Name : "verify" } },
262
+ "verifyhost" : func () ServerOption { return & ServerOptionValue {Name : "verifyhost" } },
263
+ "weight" : func () ServerOption { return & ServerOptionValue {Name : "weight" } },
264
+ "pool-low-conn" : func () ServerOption { return & ServerOptionValue {Name : "pool-low-conn" } },
265
+ "ws" : func () ServerOption { return & ServerOptionValue {Name : "ws" } },
266
+ "log-bufsize" : func () ServerOption { return & ServerOptionValue {Name : "log-bufsize" } },
267
+ "set-proxy-v2-tlv-fmt" : func () ServerOption { return & ServerOptionIDValue {Name : "set-proxy-v2-tlv-fmt" } },
268
+ "guid" : func () ServerOption { return & ServerOptionValue {Name : "guid" } },
269
+ "pool-conn-name" : func () ServerOption { return & ServerOptionValue {Name : "pool-conn-name" } },
270
+ "hash-key" : func () ServerOption { return & ServerOptionValue {Name : "hash-key" } },
271
+ }
272
+
273
+ func getServerOption (option string ) ServerOption {
274
+ option = strings .Split (option , "(" )[0 ]
275
+
276
+ if factoryMethod , found := serverOptionFactoryMethods [option ]; found {
277
+ return factoryMethod ()
272
278
}
279
+ return nil
273
280
}
274
281
275
282
// Parse ...
276
283
func ParseServerOptions (options []string ) []ServerOption {
277
284
result := []ServerOption {}
278
285
currentIndex := 0
279
286
for currentIndex < len (options ) {
280
- found := false
281
- for _ , parser := range getServerOptions () {
282
- if size , err := parser .Parse (options , currentIndex ); err == nil {
283
- result = append (result , parser )
284
- found = true
285
- currentIndex += size
286
- }
287
- }
288
- if ! found {
287
+ serverOption := getServerOption (options [currentIndex ])
288
+ if serverOption == nil {
289
289
currentIndex ++
290
+ continue
291
+ }
292
+ if size , err := serverOption .Parse (options , currentIndex ); err == nil {
293
+ result = append (result , serverOption )
294
+ currentIndex += size
290
295
}
291
296
}
292
297
return result
0 commit comments