template.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2024 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 config
  15. import (
  16. "fmt"
  17. "github.com/fatedier/frp/pkg/util/util"
  18. )
  19. type NumberPair struct {
  20. First int64
  21. Second int64
  22. }
  23. func parseNumberRangePair(firstRangeStr, secondRangeStr string) ([]NumberPair, error) {
  24. firstRangeNumbers, err := util.ParseRangeNumbers(firstRangeStr)
  25. if err != nil {
  26. return nil, err
  27. }
  28. secondRangeNumbers, err := util.ParseRangeNumbers(secondRangeStr)
  29. if err != nil {
  30. return nil, err
  31. }
  32. if len(firstRangeNumbers) != len(secondRangeNumbers) {
  33. return nil, fmt.Errorf("first and second range numbers are not in pairs")
  34. }
  35. pairs := make([]NumberPair, 0, len(firstRangeNumbers))
  36. for i := 0; i < len(firstRangeNumbers); i++ {
  37. pairs = append(pairs, NumberPair{
  38. First: firstRangeNumbers[i],
  39. Second: secondRangeNumbers[i],
  40. })
  41. }
  42. return pairs, nil
  43. }
  44. func parseNumberRange(firstRangeStr string) ([]int64, error) {
  45. return util.ParseRangeNumbers(firstRangeStr)
  46. }