MCPcopy Create free account
hub / github.com/cli/cli / NewTelemetryAPIJSONClient

Function NewTelemetryAPIJSONClient

internal/barista/observability/telemetry.twirp.go:146–177  ·  view source on GitHub ↗

NewTelemetryAPIJSONClient creates a JSON client that implements the TelemetryAPI interface. It communicates using JSON and can be configured with a custom HTTPClient.

(baseURL string, client HTTPClient, opts ...twirp.ClientOption)

Source from the content-addressed store, hash-verified

144// NewTelemetryAPIJSONClient creates a JSON client that implements the TelemetryAPI interface.
145// It communicates using JSON and can be configured with a custom HTTPClient.
146func NewTelemetryAPIJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) TelemetryAPI {
147 if c, ok := client.(*http.Client); ok {
148 client = withoutRedirects(c)
149 }
150
151 clientOpts := twirp.ClientOptions{}
152 for _, o := range opts {
153 o(&clientOpts)
154 }
155
156 // Using ReadOpt allows backwards and forwards compatibility with new options in the future
157 literalURLs := false
158 _ = clientOpts.ReadOpt("literalURLs", &literalURLs)
159 var pathPrefix string
160 if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok {
161 pathPrefix = "/twirp" // default prefix
162 }
163
164 // Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method>
165 serviceURL := sanitizeBaseURL(baseURL)
166 serviceURL += baseServicePath(pathPrefix, "clientappsfe.observability.v1", "TelemetryAPI")
167 urls := [1]string{
168 serviceURL + "RecordEvents",
169 }
170
171 return &telemetryAPIJSONClient{
172 client: client,
173 urls: urls,
174 interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...),
175 opts: clientOpts,
176 }
177}
178
179func (c *telemetryAPIJSONClient) RecordEvents(ctx context.Context, in *RecordEventsRequest) (*RecordEventsResponse, error) {
180 ctx = ctxsetters.WithPackageName(ctx, "clientappsfe.observability.v1")

Callers

nothing calls this directly

Calls 3

withoutRedirectsFunction · 0.85
sanitizeBaseURLFunction · 0.85
baseServicePathFunction · 0.85

Tested by

no test coverage detected