MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / garbageLenFuncFromValues

Function garbageLenFuncFromValues

dialer/dialer.go:93–135  ·  view source on GitHub ↗
(params url.Values)

Source from the content-addressed store, hash-verified

91}
92
93func garbageLenFuncFromValues(params url.Values) (func() int, error) {
94 if !params.Has("fetchrandom") {
95 return nil, nil
96 }
97 left, right, found := strings.Cut(params.Get("fetchrandom"), "-")
98 if found {
99 lo, err := strconv.Atoi(left)
100 if err != nil {
101 return nil, fmt.Errorf("can't convert lower boundary for garbage length %q to int: %w", left, err)
102 }
103 if lo < 0 {
104 return nil, errors.New("negative lower boundary for garbage length is not allowed")
105 }
106 hi, err := strconv.Atoi(right)
107 if err != nil {
108 return nil, fmt.Errorf("can't convert upper boundary for garbage length %q to int: %w", right, err)
109 }
110 if hi < 0 {
111 return nil, errors.New("negative upper boundary for garbage length is not allowed")
112 }
113 if hi < lo {
114 hi, lo = lo, hi
115 }
116 if hi == lo {
117 return func() int {
118 return lo
119 }, nil
120 }
121 return func() int {
122 return lo + rand.IntN(hi-lo)
123 }, nil
124 }
125 l, err := strconv.Atoi(left)
126 if err != nil {
127 return nil, fmt.Errorf("can't convert garbage length %q to int: %w", left, err)
128 }
129 if l < 0 {
130 return nil, errors.New("negative garbage length is not allowed")
131 }
132 return func() int {
133 return l
134 }, nil
135}

Callers 1

H2ProxyDialerFromURLFunction · 0.85

Calls 3

ErrorfMethod · 0.80
HasMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected