Improve the strict configuration validation (#3809)

This commit is contained in:
fatedier
2023-11-28 18:43:33 +08:00
committed by GitHub
parent 7c799ee921
commit 38f297a395
7 changed files with 102 additions and 6 deletions

View File

@@ -15,6 +15,7 @@
package v1
import (
"bytes"
"encoding/json"
"errors"
"fmt"
@@ -177,7 +178,11 @@ func (c *TypedProxyConfig) UnmarshalJSON(b []byte) error {
if configurer == nil {
return fmt.Errorf("unknown proxy type: %s", typeStruct.Type)
}
if err := json.Unmarshal(b, configurer); err != nil {
decoder := json.NewDecoder(bytes.NewBuffer(b))
if DisallowUnknownFields {
decoder.DisallowUnknownFields()
}
if err := decoder.Decode(configurer); err != nil {
return err
}
c.ProxyConfigurer = configurer