mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
config: add some validations (#3610)
This commit is contained in:
@@ -17,6 +17,8 @@ package validation
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
)
|
||||
|
||||
@@ -29,13 +31,21 @@ func validateWebServerConfig(c *v1.WebServerConfig) error {
|
||||
return fmt.Errorf("tls.keyFile must be specified when tls is enabled")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
return ValidatePort(c.Port, "webServer.port")
|
||||
}
|
||||
|
||||
// ValidatePort checks that the network port is in range
|
||||
func ValidatePort(port int) error {
|
||||
func ValidatePort(port int, fieldPath string) error {
|
||||
if 0 <= port && port <= 65535 {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("port number %d must be in the range 0..65535", port)
|
||||
return fmt.Errorf("%s: port number %d must be in the range 0..65535", fieldPath, port)
|
||||
}
|
||||
|
||||
func validateLogConfig(c *v1.LogConfig) error {
|
||||
if !lo.Contains(supportedLogLevels, c.Level) {
|
||||
return fmt.Errorf("invalid log level, optional values are %v", supportedLogLevels)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user