Codebase list golang-github-bluebreezecf-opentsdb-goclient / 0749eef
[ Debian Janitor ] New upstream snapshot. Debian Janitor 1 year, 3 months ago
2 changed file(s) with 38 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
2323 package client
2424
2525 import (
26 "context"
2627 "encoding/json"
2728 "errors"
2829 "fmt"
426427 return &clientImpl, nil
427428 }
428429
430 // ClientContext implements the Client interface and additionally provides a
431 // way to return a client that is associated with the given context.
432 type ClientContext interface {
433 // WithContext returns a Client that is associated with the given context.
434 // Use this to pass a context to underlying transport (e.g. to specify a
435 // deadline).
436 WithContext(ctx context.Context) Client
437 Client
438 }
439
440 func NewClientContext(opentsdbCfg config.OpenTSDBConfig) (Client, error) {
441 client, err := NewClient(opentsdbCfg)
442 if err != nil {
443 return nil, err
444 }
445 // We know this is actually clientImpl and implements this interface.
446 return client.(ClientContext), nil
447 }
448
429449 // The private implementation of Client interface.
430450 type clientImpl struct {
431451 tsdbEndpoint string
432452 client *http.Client
453 ctx context.Context
433454 opentsdbCfg config.OpenTSDBConfig
434455 }
435456
452473 // Return the contents of the specific Response instance with
453474 // the string format
454475 String() string
476 }
477
478 func (c *clientImpl) WithContext(ctx context.Context) Client {
479 return &clientImpl{
480 tsdbEndpoint: c.tsdbEndpoint,
481 client: c.client,
482 ctx: ctx,
483 opentsdbCfg: c.opentsdbCfg,
484 }
455485 }
456486
457487 // sendRequest dispatches the http request with the given method name, url and body contents.
460490 // response with the specific type. Otherwise, the returned error is not nil.
461491 func (c *clientImpl) sendRequest(method, url, reqBodyCnt string, parsedResp Response) error {
462492 req, err := http.NewRequest(method, url, strings.NewReader(reqBodyCnt))
493 if c.ctx != nil {
494 req = req.WithContext(c.ctx)
495 }
463496 if err != nil {
464497 return errors.New(fmt.Sprintf("Failed to create request for %s %s: %v", method, url, err))
465498 }
0 golang-github-bluebreezecf-opentsdb-goclient (0.0~git20160515.0.539764b-2) UNRELEASED; urgency=medium
0 golang-github-bluebreezecf-opentsdb-goclient (0.0~git20190921.0.7961383-1) UNRELEASED; urgency=medium
11
22 [ Alexandre Viau ]
33 * Point Vcs-* urls to salsa.debian.org.
55 [ Jelmer Vernooij ]
66 * Use secure copyright file specification URI.
77
8 -- Alexandre Viau <aviau@debian.org> Mon, 02 Apr 2018 14:57:48 -0400
8 [ Debian Janitor ]
9 * New upstream snapshot.
10
11 -- Alexandre Viau <aviau@debian.org> Thu, 19 Jan 2023 01:28:42 -0000
912
1013 golang-github-bluebreezecf-opentsdb-goclient (0.0~git20160515.0.539764b-1) unstable; urgency=medium
1114