MCPcopy
hub / github.com/netdata/netdata / parseFunction

Method parseFunction

src/go/plugin/framework/functions/parser.go:188–226  ·  view source on GitHub ↗
(line string)

Source from the content-addressed store, hash-verified

186}
187
188func (p *inputParser) parseFunction(line string) (*Function, error) {
189 r := csv.NewReader(strings.NewReader(line))
190 r.Comma = ' '
191
192 parts, err := r.Read()
193 if err != nil {
194 return nil, fmt.Errorf("failed to parse CSV: %w", err)
195 }
196
197 if n := len(parts); n != 6 && n != 7 {
198 return nil, fmt.Errorf("unexpected number of parts: want 6 or 7, got %d", n)
199 }
200
201 timeout, err := strconv.ParseInt(parts[2], 10, 64)
202 if err != nil {
203 return nil, fmt.Errorf("invalid timeout value: %w", err)
204 }
205
206 nameAndArgs := strings.Split(parts[3], " ")
207 if len(nameAndArgs) == 0 {
208 return nil, fmt.Errorf("empty function name and arguments")
209 }
210
211 fn := &Function{
212 key: parts[0],
213 UID: parts[1],
214 Timeout: time.Duration(timeout) * time.Second,
215 Name: nameAndArgs[0],
216 Args: nameAndArgs[1:],
217 Permissions: parts[4],
218 Source: parts[5],
219 }
220
221 if len(parts) == 7 {
222 fn.ContentType = parts[6]
223 }
224
225 return fn, nil
226}

Callers 1

parseEventMethod · 0.95

Calls 3

ReadMethod · 0.95
ErrorfMethod · 0.65
DurationMethod · 0.45

Tested by

no test coverage detected