MCPcopy
hub / github.com/github/gh-ost / ParseLoadMap

Function ParseLoadMap

go/base/load_map.go:28–51  ·  view source on GitHub ↗

NewLoadMap parses a `--*-load` flag (e.g. `--max-load`), which is in multiple key-value format, such as: 'Threads_running=100,Threads_connected=500'

(loadList string)

Source from the content-addressed store, hash-verified

26//
27// 'Threads_running=100,Threads_connected=500'
28func ParseLoadMap(loadList string) (LoadMap, error) {
29 result := NewLoadMap()
30 if loadList == "" {
31 return result, nil
32 }
33
34 loadConditions := strings.Split(loadList, ",")
35 for _, loadCondition := range loadConditions {
36 loadTokens := strings.Split(loadCondition, "=")
37 if len(loadTokens) != 2 {
38 return result, fmt.Errorf("Error parsing load condition: %s", loadCondition)
39 }
40 if loadTokens[0] == "" {
41 return result, fmt.Errorf("Error parsing status variable in load condition: %s", loadCondition)
42 }
43 if n, err := strconv.ParseInt(loadTokens[1], 10, 0); err != nil {
44 return result, fmt.Errorf("Error parsing numeric value in load condition: %s", loadCondition)
45 } else {
46 result[loadTokens[0]] = n
47 }
48 }
49
50 return result, nil
51}
52
53// Duplicate creates a clone of this map
54func (lm *LoadMap) Duplicate() LoadMap {

Callers 4

TestParseLoadMapFunction · 0.85
TestStringFunction · 0.85
ReadMaxLoadMethod · 0.85
ReadCriticalLoadMethod · 0.85

Calls 2

NewLoadMapFunction · 0.85
ErrorfMethod · 0.65

Tested by 2

TestParseLoadMapFunction · 0.68
TestStringFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…