mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
Improve the strict configuration validation (#3809)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -108,7 +109,11 @@ func (c *TypedVisitorConfig) UnmarshalJSON(b []byte) error {
|
||||
if configurer == nil {
|
||||
return fmt.Errorf("unknown visitor 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.VisitorConfigurer = configurer
|
||||
@@ -120,7 +125,9 @@ func NewVisitorConfigurerByType(t VisitorType) VisitorConfigurer {
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return reflect.New(v).Interface().(VisitorConfigurer)
|
||||
vc := reflect.New(v).Interface().(VisitorConfigurer)
|
||||
vc.GetBaseConfig().Type = string(t)
|
||||
return vc
|
||||
}
|
||||
|
||||
var _ VisitorConfigurer = &STCPVisitorConfig{}
|
||||
|
||||
Reference in New Issue
Block a user