Standard library / runtime/pprof
pprof.Label()
Look up a label in the context. The boolean distinguishes absent keys from empty values. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Label(ctx context.Context, key string) (string, bool)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | Context carrying profiling labels or an execution trace task. |
| key | string | Label key to look up. |
Return Value
(string, bool)
Label value and whether the key exists.
Working Example
Example Snippetgo
package main
import ( "context" "fmt" "runtime/pprof")
func main() { c := pprof.WithLabels(context.Background(), pprof.Labels("phase", "")) v, ok := pprof.Label(c, "phase") fmt.Println(v == "" && ok)}