github.com/blend/go-sdk@v1.20220411.3/r2/context.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package r2
     9  
    10  import (
    11  	"context"
    12  )
    13  
    14  type parameterizedPathKey struct{}
    15  
    16  // WithParameterizedPath adds a path with named parameters to a context. Useful for
    17  // outbound request aggregation for metrics and tracing when route parameters
    18  // are involved.
    19  func WithParameterizedPath(ctx context.Context, path string) context.Context {
    20  	return context.WithValue(ctx, parameterizedPathKey{}, path)
    21  }
    22  
    23  // GetParameterizedPath gets a path with named parameters off a context. Useful for
    24  // outbound request aggregation for metrics and tracing when route parameters
    25  // are involved. Relies on OptParameterizedPath being added to a Request.
    26  func GetParameterizedPath(ctx context.Context) string {
    27  	path, _ := ctx.Value(parameterizedPathKey{}).(string)
    28  	return path
    29  }