Skip to content

Commit d2de8b0

Browse files
committedOct 4, 2019
Cleanup code
This commit cleans up a few warnings by staticcheck. It also adds a `types-removal=true|false` (default is `false`) that, when disabled, ignores deprecation warnings due to types removal in 7.x.
1 parent 0f7dc05 commit d2de8b0

14 files changed

+16
-36
lines changed
 

‎bulk.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ func (s *BulkService) Pretty(pretty bool) *BulkService {
132132
// Add adds bulkable requests, i.e. BulkIndexRequest, BulkUpdateRequest,
133133
// and/or BulkDeleteRequest.
134134
func (s *BulkService) Add(requests ...BulkableRequest) *BulkService {
135-
for _, r := range requests {
136-
s.requests = append(s.requests, r)
137-
}
135+
s.requests = append(s.requests, requests...)
138136
return s
139137
}
140138

‎client.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ func (c *Client) extractHostname(scheme, address string) string {
995995
if idx := strings.Index(s, "/"); idx >= 0 {
996996
s = s[idx+1:]
997997
}
998-
if strings.Index(s, ":") < 0 {
998+
if !strings.Contains(s, ":") {
999999
return ""
10001000
}
10011001
return fmt.Sprintf("%s://%s", scheme, s)
@@ -1160,11 +1160,9 @@ func (c *Client) startupHealthcheck(parentCtx context.Context, timeout time.Dura
11601160
case <-parentCtx.Done():
11611161
lastErr = parentCtx.Err()
11621162
done = true
1163-
break
11641163
case <-time.After(1 * time.Second):
11651164
if time.Since(start) > timeout {
11661165
done = true
1167-
break
11681166
}
11691167
}
11701168
}

‎client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ func TestPerformRequestWithMaxResponseSize(t *testing.T) {
12861286
t.Fatal("expected response to be != nil")
12871287
}
12881288

1289-
res, err = client.PerformRequest(context.TODO(), PerformRequestOptions{
1289+
_, err = client.PerformRequest(context.TODO(), PerformRequestOptions{
12901290
Method: "GET",
12911291
Path: "/",
12921292
MaxResponseSize: 100,

‎decoder_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
)
1414

1515
type decoder struct {
16-
dec json.Decoder
17-
1816
N int64
1917
}
2018

‎highlight.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (hl *Highlight) Source() (interface{}, error) {
238238
source["fields"] = fields
239239
} else {
240240
// Use a map for the fields
241-
fields := make(map[string]interface{}, 0)
241+
fields := make(map[string]interface{})
242242
for _, field := range hl.fields {
243243
src, err := field.Source()
244244
if err != nil {

‎search_aggs_bucket_significant_terms.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type SignificantTermsAggregation struct {
2323

2424
func NewSignificantTermsAggregation() *SignificantTermsAggregation {
2525
return &SignificantTermsAggregation{
26-
subAggregations: make(map[string]Aggregation, 0),
26+
subAggregations: make(map[string]Aggregation),
2727
}
2828
}
2929

‎search_aggs_bucket_significant_text.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type SignificantTextAggregation struct {
2222

2323
func NewSignificantTextAggregation() *SignificantTextAggregation {
2424
return &SignificantTextAggregation{
25-
subAggregations: make(map[string]Aggregation, 0),
25+
subAggregations: make(map[string]Aggregation),
2626
}
2727
}
2828

‎search_aggs_bucket_terms.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type TermsAggregation struct {
3030

3131
func NewTermsAggregation() *TermsAggregation {
3232
return &TermsAggregation{
33-
subAggregations: make(map[string]Aggregation, 0),
33+
subAggregations: make(map[string]Aggregation),
3434
}
3535
}
3636

‎search_aggs_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ func TestAggsCompositeIntegration(t *testing.T) {
13431343
t.Fatalf("expected %d; got: %d", want, have)
13441344
}
13451345
afterKey = compositeAggRes.AfterKey
1346-
if afterKey == nil || len(afterKey) == 0 {
1346+
if len(afterKey) == 0 {
13471347
t.Fatalf("expected after_key; got: %v", afterKey)
13481348
}
13491349
if v, found := afterKey["composite_users"]; !found {
@@ -1396,7 +1396,7 @@ func TestAggsCompositeIntegration(t *testing.T) {
13961396
t.Fatalf("expected %d; got: %d", want, have)
13971397
}
13981398
afterKey = compositeAggRes.AfterKey
1399-
if afterKey == nil || len(afterKey) == 0 {
1399+
if len(afterKey) == 0 {
14001400
t.Fatalf("expected after_key; got: %v", afterKey)
14011401
}
14021402
if v, found := afterKey["composite_users"]; !found {

‎setup_test.go

+6-16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"math/rand"
1515
"net/http"
1616
"os"
17+
"strings"
1718
"time"
1819
)
1920

@@ -237,16 +238,6 @@ func (t tweet) String() string {
237238
return fmt.Sprintf("tweet{User:%q,Message:%q,Retweets:%d}", t.User, t.Message, t.Retweets)
238239
}
239240

240-
type comment struct {
241-
User string `json:"user"`
242-
Comment string `json:"comment"`
243-
Created time.Time `json:"created,omitempty"`
244-
}
245-
246-
func (c comment) String() string {
247-
return fmt.Sprintf("comment{User:%q,Comment:%q}", c.User, c.Comment)
248-
}
249-
250241
type joinDoc struct {
251242
Message string `json:"message"`
252243
JoinField interface{} `json:"my_join_field,omitempty"`
@@ -273,11 +264,6 @@ type doctype struct {
273264
Message string `json:"message"`
274265
}
275266

276-
// queries is required for Percolate tests.
277-
type queries struct {
278-
Query string `json:"query"`
279-
}
280-
281267
func isTravis() bool {
282268
return os.Getenv("TRAVIS") != ""
283269
}
@@ -308,6 +294,7 @@ func (d *strictDecoder) Decode(data []byte, v interface{}) error {
308294

309295
var (
310296
logDeprecations = flag.String("deprecations", "off", "log or fail on deprecation warnings")
297+
logTypesRemoval = flag.Bool("types-removal", false, "log deprecation warnings regarding types removal")
311298
strict = flag.Bool("strict-decoder", false, "treat missing unknown fields in response as errors")
312299
)
313300

@@ -319,7 +306,7 @@ func setupTestClient(t logger, options ...ClientOptionFunc) (client *Client) {
319306
t.Fatal(err)
320307
}
321308

322-
// Add a strict decoder (unless a specific decoder has been specified already)
309+
// Use strict JSON decoder (unless a specific decoder has been specified already)
323310
if *strict {
324311
if client.decoder == nil {
325312
client.decoder = &strictDecoder{}
@@ -332,6 +319,9 @@ func setupTestClient(t logger, options ...ClientOptionFunc) (client *Client) {
332319
if loglevel := *logDeprecations; loglevel != "off" {
333320
logDeprecation = func(req *http.Request, res *http.Response) {
334321
for _, warning := range res.Header["Warning"] {
322+
if !*logTypesRemoval && strings.Contains(warning, "[types removal]") {
323+
continue
324+
}
335325
switch loglevel {
336326
default:
337327
t.Logf("[%s] Deprecation warning: %s", req.URL, warning)

‎suggester_completion.go

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type CompletionSuggester struct {
2121
size *int
2222
shardSize *int
2323
contextQueries []SuggesterContextQuery
24-
payload interface{}
2524

2625
fuzzyOptions *FuzzyCompletionSuggesterOptions
2726
regexOptions *RegexCompletionSuggesterOptions

‎xpack_info.go

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
type XPackInfoService struct {
1919
client *Client
2020
pretty bool
21-
name string
2221
}
2322

2423
// NewXPackInfoService creates a new XPackInfoService.

‎xpack_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func TestXPackWatcher(t *testing.T) {
315315
if err != nil {
316316
t.Fatal(err)
317317
}
318-
stats, err = client.XPackWatchStats().Do(context.Background())
318+
_, err = client.XPackWatchStats().Do(context.Background())
319319
if err != nil {
320320
t.Fatal(err)
321321
}

‎xpack_watcher_deactivate_watch.go

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ type XPackWatcherDeactivateWatchService struct {
2020
pretty bool
2121
watchId string
2222
masterTimeout string
23-
bodyJson interface{}
24-
bodyString string
2523
}
2624

2725
// NewXPackWatcherDeactivateWatchService creates a new XPackWatcherDeactivateWatchService.

0 commit comments

Comments
 (0)