1
0

common.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2023 The frp Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package validation
  15. import (
  16. "fmt"
  17. v1 "github.com/fatedier/frp/pkg/config/v1"
  18. )
  19. func validateWebServerConfig(c *v1.WebServerConfig) error {
  20. if c.TLS != nil {
  21. if c.TLS.CertFile == "" {
  22. return fmt.Errorf("tls.certFile must be specified when tls is enabled")
  23. }
  24. if c.TLS.KeyFile == "" {
  25. return fmt.Errorf("tls.keyFile must be specified when tls is enabled")
  26. }
  27. }
  28. return nil
  29. }
  30. // ValidatePort checks that the network port is in range
  31. func ValidatePort(port int) error {
  32. if 0 <= port && port <= 65535 {
  33. return nil
  34. }
  35. return fmt.Errorf("port number %d must be in the range 0..65535", port)
  36. }