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

Function NewTelemetryAPIServer

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

NewTelemetryAPIServer builds a TwirpServer that can be used as an http.Handler to handle HTTP requests that are routed to the right method in the provided svc implementation. The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks).

(svc TelemetryAPI, opts ...interface{})

Source from the content-addressed store, hash-verified

239// HTTP requests that are routed to the right method in the provided svc implementation.
240// The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks).
241func NewTelemetryAPIServer(svc TelemetryAPI, opts ...interface{}) TwirpServer {
242 serverOpts := newServerOpts(opts)
243
244 // Using ReadOpt allows backwards and forwards compatibility with new options in the future
245 jsonSkipDefaults := false
246 _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults)
247 jsonCamelCase := false
248 _ = serverOpts.ReadOpt("jsonCamelCase", &jsonCamelCase)
249 var pathPrefix string
250 if ok := serverOpts.ReadOpt("pathPrefix", &pathPrefix); !ok {
251 pathPrefix = "/twirp" // default prefix
252 }
253
254 return &telemetryAPIServer{
255 TelemetryAPI: svc,
256 hooks: serverOpts.Hooks,
257 interceptor: twirp.ChainInterceptors(serverOpts.Interceptors...),
258 pathPrefix: pathPrefix,
259 jsonSkipDefaults: jsonSkipDefaults,
260 jsonCamelCase: jsonCamelCase,
261 }
262}
263
264// writeError writes an HTTP response with a valid Twirp error format, and triggers hooks.
265// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err)

Callers 2

TestRunSendTelemetryFunction · 0.92

Calls 1

newServerOptsFunction · 0.85

Tested by 2

TestRunSendTelemetryFunction · 0.74