diff --git a/CHANGELOG.md b/CHANGELOG.md index 6639b4cd..27adce16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.2.0 +## Breaking Change + - [#107](https://github.com/influxdata/influxdb-client-go/pull/100) Renamed `InfluxDBClient` interface to `Client`, so the full name `influxdb2.Client` suits better to Go naming conventions + ## 1.1.0 [2020-04-24] ### Features 1. [#100](https://github.com/influxdata/influxdb-client-go/pull/100) HTTP request timeout made configurable diff --git a/client.go b/client.go index 990c47d7..e9c0bfe6 100644 --- a/client.go +++ b/client.go @@ -20,11 +20,11 @@ import ( ihttp "github.com/influxdata/influxdb-client-go/internal/http" ) -// InfluxDBClient provides API to communicate with InfluxDBServer +// Client provides API to communicate with InfluxDBServer // There two APIs for writing, WriteApi and WriteApiBlocking. // WriteApi provides asynchronous, non-blocking, methods for writing time series data. // WriteApiBlocking provides blocking methods for writing time series data -type InfluxDBClient interface { +type Client interface { // WriteApi returns the asynchronous, non-blocking, Write client. WriteApi(org, bucket string) WriteApi // WriteApi returns the synchronous, blocking, Write client. @@ -51,8 +51,8 @@ type InfluxDBClient interface { Ready(ctx context.Context) (bool, error) } -// client implements InfluxDBClient interface -type client struct { +// clientImpl implements Client interface +type clientImpl struct { serverUrl string options *Options writeApis []WriteApi @@ -63,19 +63,19 @@ type client struct { usersApi api.UsersApi } -// NewClient creates InfluxDBClient for connecting to given serverUrl with provided authentication token, with default options +// NewClient creates Client for connecting to given serverUrl with provided authentication token, with the default options. // Authentication token can be empty in case of connecting to newly installed InfluxDB server, which has not been set up yet. // In such case Setup will set authentication token -func NewClient(serverUrl string, authToken string) InfluxDBClient { +func NewClient(serverUrl string, authToken string) Client { return NewClientWithOptions(serverUrl, authToken, DefaultOptions()) } -// NewClientWithOptions creates InfluxDBClient for connecting to given serverUrl with provided authentication token +// NewClientWithOptions creates Client for connecting to given serverUrl with provided authentication token // and configured with custom Options // Authentication token can be empty in case of connecting to newly installed InfluxDB server, which has not been set up yet. // In such case Setup will set authentication token -func NewClientWithOptions(serverUrl string, authToken string, options *Options) InfluxDBClient { - client := &client{ +func NewClientWithOptions(serverUrl string, authToken string, options *Options) Client { + client := &clientImpl{ serverUrl: serverUrl, options: options, writeApis: make([]WriteApi, 0, 5), @@ -83,15 +83,15 @@ func NewClientWithOptions(serverUrl string, authToken string, options *Options) } return client } -func (c *client) Options() *Options { +func (c *clientImpl) Options() *Options { return c.options } -func (c *client) ServerUrl() string { +func (c *clientImpl) ServerUrl() string { return c.serverUrl } -func (c *client) Ready(ctx context.Context) (bool, error) { +func (c *clientImpl) Ready(ctx context.Context) (bool, error) { readyUrl, err := url.Parse(c.serverUrl) if err != nil { return false, err @@ -111,28 +111,28 @@ func (c *client) Ready(ctx context.Context) (bool, error) { return readyRes, nil } -func (c *client) WriteApi(org, bucket string) WriteApi { +func (c *clientImpl) WriteApi(org, bucket string) WriteApi { w := newWriteApiImpl(org, bucket, c.httpService, c) c.writeApis = append(c.writeApis, w) return w } -func (c *client) WriteApiBlocking(org, bucket string) WriteApiBlocking { +func (c *clientImpl) WriteApiBlocking(org, bucket string) WriteApiBlocking { w := newWriteApiBlockingImpl(org, bucket, c.httpService, c) return w } -func (c *client) Close() { +func (c *clientImpl) Close() { for _, w := range c.writeApis { w.Close() } } -func (c *client) QueryApi(org string) QueryApi { +func (c *clientImpl) QueryApi(org string) QueryApi { return newQueryApi(org, c.httpService, c) } -func (c *client) AuthorizationsApi() api.AuthorizationsApi { +func (c *clientImpl) AuthorizationsApi() api.AuthorizationsApi { c.lock.Lock() defer c.lock.Unlock() if c.authApi == nil { @@ -141,7 +141,7 @@ func (c *client) AuthorizationsApi() api.AuthorizationsApi { return c.authApi } -func (c *client) OrganizationsApi() api.OrganizationsApi { +func (c *clientImpl) OrganizationsApi() api.OrganizationsApi { c.lock.Lock() defer c.lock.Unlock() if c.orgApi == nil { @@ -150,7 +150,7 @@ func (c *client) OrganizationsApi() api.OrganizationsApi { return c.orgApi } -func (c *client) UsersApi() api.UsersApi { +func (c *clientImpl) UsersApi() api.UsersApi { c.lock.Lock() defer c.lock.Unlock() if c.usersApi == nil { diff --git a/query.go b/query.go index c0cb35e5..d93b156a 100644 --- a/query.go +++ b/query.go @@ -47,7 +47,7 @@ type QueryApi interface { Query(ctx context.Context, query string) (*QueryTableResult, error) } -func newQueryApi(org string, service ihttp.Service, client InfluxDBClient) QueryApi { +func newQueryApi(org string, service ihttp.Service, client Client) QueryApi { return &queryApiImpl{ org: org, httpService: service, @@ -59,7 +59,7 @@ func newQueryApi(org string, service ihttp.Service, client InfluxDBClient) Query type queryApiImpl struct { org string httpService ihttp.Service - client InfluxDBClient + client Client url string lock sync.Mutex } diff --git a/setup.go b/setup.go index 9f2a6466..a6bd5e40 100644 --- a/setup.go +++ b/setup.go @@ -16,7 +16,7 @@ import ( "path" ) -func (c *client) Setup(ctx context.Context, username, password, org, bucket string, retentionPeriodHours int) (*domain.OnboardingResponse, error) { +func (c *clientImpl) Setup(ctx context.Context, username, password, org, bucket string, retentionPeriodHours int) (*domain.OnboardingResponse, error) { if username == "" || password == "" { return nil, errors.New("a username and password is required for a setup") } @@ -42,11 +42,13 @@ func (c *client) Setup(ctx context.Context, username, password, org, bucket stri } u.Path = path.Join(u.Path, "setup") - error := c.httpService.PostRequest(ctx, u.String(), bytes.NewReader(inputData), func(req *http.Request) { + perror := c.httpService.PostRequest(ctx, u.String(), bytes.NewReader(inputData), func(req *http.Request) { req.Header.Add("Content-Type", "application/json; charset=utf-8") }, func(resp *http.Response) error { - defer resp.Body.Close() + defer func() { + _ = resp.Body.Close() + }() setupResponse := &domain.OnboardingResponse{} if err := json.NewDecoder(resp.Body).Decode(setupResponse); err != nil { return err @@ -58,8 +60,8 @@ func (c *client) Setup(ctx context.Context, username, password, org, bucket stri return nil }, ) - if error != nil { - return nil, error + if perror != nil { + return nil, perror } return setupResult, nil } diff --git a/write.go b/write.go index d81b59e1..34d1f7b6 100644 --- a/write.go +++ b/write.go @@ -48,7 +48,7 @@ type writeBuffInfoReq struct { writeBuffLen int } -func newWriteApiImpl(org string, bucket string, service http.Service, client InfluxDBClient) *writeApiImpl { +func newWriteApiImpl(org string, bucket string, service http.Service, client Client) *writeApiImpl { w := &writeApiImpl{ service: newWriteService(org, bucket, service, client), writeBuffer: make([]string, 0, client.Options().BatchSize()+1), @@ -137,7 +137,7 @@ func (w *writeApiImpl) flushBuffer() { w.writeCh <- batch // lines = lines[:0] //}(w.writeBuffer) - //w.writeBuffer = make([]string,0, w.service.client.Options.BatchSize+1) + //w.writeBuffer = make([]string,0, w.service.clientImpl.Options.BatchSize+1) w.writeBuffer = w.writeBuffer[:0] } } @@ -201,7 +201,7 @@ func (w *writeApiImpl) WriteRecord(line string) { } func (w *writeApiImpl) WritePoint(point *Point) { - //w.bufferCh <- point.ToLineProtocol(w.service.client.Options().Precision) + //w.bufferCh <- point.ToLineProtocol(w.service.clientImpl.Options().Precision) line, err := w.service.encodePoints(point) if err != nil { logger.Errorf("point encoding error: %s\n", err.Error()) diff --git a/writeApiBlocking.go b/writeApiBlocking.go index 1ace5776..2e042283 100644 --- a/writeApiBlocking.go +++ b/writeApiBlocking.go @@ -28,7 +28,7 @@ type writeApiBlockingImpl struct { } // creates writeApiBlockingImpl for org and bucket with underlying client -func newWriteApiBlockingImpl(org string, bucket string, service http.Service, client InfluxDBClient) *writeApiBlockingImpl { +func newWriteApiBlockingImpl(org string, bucket string, service http.Service, client Client) *writeApiBlockingImpl { return &writeApiBlockingImpl{service: newWriteService(org, bucket, service, client)} } diff --git a/writeService.go b/writeService.go index 93303808..a75bd57e 100644 --- a/writeService.go +++ b/writeService.go @@ -36,10 +36,10 @@ type writeService struct { lastWriteAttempt time.Time retryQueue *queue lock sync.Mutex - client InfluxDBClient + client Client } -func newWriteService(org string, bucket string, httpService ihttp.Service, client InfluxDBClient) *writeService { +func newWriteService(org string, bucket string, httpService ihttp.Service, client Client) *writeService { logger.SetDebugLevel(client.Options().LogLevel()) retryBufferLimit := client.Options().RetryBufferLimit() / client.Options().BatchSize() if retryBufferLimit == 0 { diff --git a/write_test.go b/write_test.go index 46b4c5bb..1a4eba6a 100644 --- a/write_test.go +++ b/write_test.go @@ -62,13 +62,13 @@ func (t *testHttpService) ReplyError() *ihttp.Error { return t.replyError } -func (t *testHttpService) SetAuthorization(authorization string) { +func (t *testHttpService) SetAuthorization(_ string) { } func (t *testHttpService) GetRequest(_ context.Context, _ string, _ ihttp.RequestCallback, _ ihttp.ResponseCallback) *ihttp.Error { return nil } -func (t *testHttpService) DoHttpRequest(req *http.Request, requestCallback ihttp.RequestCallback, _ ihttp.ResponseCallback) *ihttp.Error { +func (t *testHttpService) DoHttpRequest(_ *http.Request, _ ihttp.RequestCallback, _ ihttp.ResponseCallback) *ihttp.Error { return nil } @@ -121,11 +121,11 @@ func (t *testHttpService) Lines() []string { return t.lines } -func newTestClient() *client { - return &client{serverUrl: "http://locahost:4444", options: DefaultOptions()} +func newTestClient() *clientImpl { + return &clientImpl{serverUrl: "http://locahost:4444", options: DefaultOptions()} } -func newTestService(t *testing.T, client InfluxDBClient) *testHttpService { +func newTestService(t *testing.T, client Client) *testHttpService { return &testHttpService{ t: t, options: client.Options(),