Standard library / net/http/httptrace

httptrace.ContextClientTrace()

Retrieve the trace associated with a context, or nil if none is registered. Do not invoke transport hooks yourself except in isolated unit tests. Expected stdout: 'true\ntrue\n'.

Formal Syntax & Structure

go syntaxgo
func ContextClientTrace(ctx context.Context) *ClientTrace

Parameters & Attributes

NameTypeDescription
ctxcontext.ContextParent or request context carrying trace hooks.

Return Value

*ClientTrace

Associated trace pointer, or nil when absent.

Working Example

Example Snippetgo
package main
import (  "context"  "fmt"  "net/http/httptrace")
func main() {  ctx := context.Background()  fmt.Println(httptrace.ContextClientTrace(ctx) == nil)  ctx = httptrace.WithClientTrace(ctx, &httptrace.ClientTrace{})  fmt.Println(httptrace.ContextClientTrace(ctx) != nil)}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference