MCPcopy Create free account
hub / github.com/devld/go-drive / parsePoolConfig

Function parsePoolConfig

drive/script/utils.go:190–228  ·  view source on GitHub ↗

parsePoolConfig parses config like this: MaxTotal,MaxIdle,MinIdle,IdleTime

(arg string)

Source from the content-addressed store, hash-verified

188
189// parsePoolConfig parses config like this: MaxTotal,MaxIdle,MinIdle,IdleTime
190func parsePoolConfig(arg string) (*s.VMPoolConfig, error) {
191 args := strings.Split(strings.ReplaceAll(arg, " ", ""), ",")
192 c := &s.VMPoolConfig{
193 MaxTotal: DefaultPoolMaxTotal,
194 MaxIdle: DefaultPoolMaxIdle,
195 MinIdle: DefaultPoolMinIdle,
196 IdleTime: DefaultPoolIdleTime,
197 }
198
199 if len(args) > 0 {
200 c.MaxTotal = types.SV(args[0]).Int(DefaultPoolMaxTotal)
201 }
202 if len(args) > 1 {
203 c.MaxIdle = types.SV(args[1]).Int(DefaultPoolMaxIdle)
204 }
205 if len(args) > 2 {
206 c.MinIdle = types.SV(args[2]).Int(DefaultPoolMinIdle)
207 }
208 if len(args) > 3 {
209 c.IdleTime = types.SV(args[3]).Duration(DefaultPoolIdleTime)
210 }
211
212 if c.MaxIdle < c.MinIdle {
213 return nil, errors.New("MaxIdle must be greater than or equal to MinIdle")
214 }
215 if c.MaxTotal <= 0 {
216 return nil, errors.New("MaxTotal must be greater than zero")
217 }
218 if c.MaxIdle < 0 {
219 return nil, errors.New("MaxIdle must not be negative")
220 }
221 if c.MinIdle < 0 {
222 return nil, errors.New("MinIdle must not be negative")
223 }
224 if c.MaxTotal < c.MinIdle {
225 return nil, errors.New("MaxTotal must be greater than or equal to MinIdle")
226 }
227 return c, nil
228}
229
230func newScriptDriveUtils(utils drive_util.DriveUtils) *scriptDriveUtils {
231 return &scriptDriveUtils{utils.CreateCache, driveDataStore{utils.Data}, utils.Config}

Callers 2

newScriptDriveFunction · 0.85

Calls 3

SVTypeAlias · 0.92
IntMethod · 0.80
DurationMethod · 0.80

Tested by 1