writeLabelPairs converts a slice of LabelPair proto messages plus the explicitly given additional label pair into text formatted as required by the text format and writes it to 'w'. An empty slice in combination with an empty string 'additionalLabelName' results in nothing being written. Otherwise,
( w enhancedWriter, in []*dto.LabelPair, additionalLabelName string, additionalLabelValue float64, )
| 338 | // in '{...}'. The function returns the number of bytes written and any error |
| 339 | // encountered. |
| 340 | func writeLabelPairs( |
| 341 | w enhancedWriter, |
| 342 | in []*dto.LabelPair, |
| 343 | additionalLabelName string, additionalLabelValue float64, |
| 344 | ) (int, error) { |
| 345 | if len(in) == 0 && additionalLabelName == "" { |
| 346 | return 0, nil |
| 347 | } |
| 348 | var ( |
| 349 | written int |
| 350 | separator byte = '{' |
| 351 | ) |
| 352 | for _, lp := range in { |
| 353 | err := w.WriteByte(separator) |
| 354 | written++ |
| 355 | if err != nil { |
| 356 | return written, err |
| 357 | } |
| 358 | n, err := w.WriteString(lp.GetName()) |
| 359 | written += n |
| 360 | if err != nil { |
| 361 | return written, err |
| 362 | } |
| 363 | n, err = w.WriteString(`="`) |
| 364 | written += n |
| 365 | if err != nil { |
| 366 | return written, err |
| 367 | } |
| 368 | n, err = writeEscapedString(w, lp.GetValue(), true) |
| 369 | written += n |
| 370 | if err != nil { |
| 371 | return written, err |
| 372 | } |
| 373 | err = w.WriteByte('"') |
| 374 | written++ |
| 375 | if err != nil { |
| 376 | return written, err |
| 377 | } |
| 378 | separator = ',' |
| 379 | } |
| 380 | if additionalLabelName != "" { |
| 381 | err := w.WriteByte(separator) |
| 382 | written++ |
| 383 | if err != nil { |
| 384 | return written, err |
| 385 | } |
| 386 | n, err := w.WriteString(additionalLabelName) |
| 387 | written += n |
| 388 | if err != nil { |
| 389 | return written, err |
| 390 | } |
| 391 | n, err = w.WriteString(`="`) |
| 392 | written += n |
| 393 | if err != nil { |
| 394 | return written, err |
| 395 | } |
| 396 | n, err = writeFloat(w, additionalLabelValue) |
| 397 | written += n |
no test coverage detected