Skip to content

Commit

Permalink
Merge branch 'release/1.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
RMPall committed Jan 11, 2022
2 parents 2d59e84 + 0c2b709 commit d74fea8
Show file tree
Hide file tree
Showing 37 changed files with 367 additions and 562 deletions.
93 changes: 93 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# This file was inspired by the golangci-lint one:
# https://github.com/golangci/golangci-lint/blob/master/.golangci.yml
run:
# default concurrency is a available CPU number
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 15
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: UK
lll:
line-length: 140
gofmt:
simplify: false
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- wrapperFunc
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- hugeParam
funlen:
# lines: 100
# statements: 100

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- deadcode
- depguard
- dogsled
- errcheck
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- revive
- gosec
- gosimple
- govet
- ineffassign
- nakedret
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- varcheck
- whitespace
- gocognit
- prealloc

issues:
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
new: false

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.43.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ audit:

.PHONY: lint
lint:
exit
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run ./...

.PHONY: build
build:
Expand Down
3 changes: 1 addition & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
update = auth.Permissions{Update: true}
)

//SearchAPI provides an API around elasticseach
// SearchAPI provides an API around elasticseach
type SearchAPI struct {
Router *mux.Router
QueryBuilder QueryBuilder
Expand All @@ -36,7 +36,6 @@ type AuthHandler interface {
type ElasticSearcher interface {
Search(ctx context.Context, index string, docType string, request []byte) ([]byte, error)
MultiSearch(ctx context.Context, index string, docType string, request []byte) ([]byte, error)
GetStatus(ctx context.Context) ([]byte, error)
}

// QueryBuilder provides methods for the search package
Expand Down
8 changes: 5 additions & 3 deletions api/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func DataLookupHandlerFunc(elasticSearchClient ElasticSearcher) http.HandlerFunc
}

responseData := dataLookupResponse{Responses: make([]interface{}, 1)}
if err := json.Unmarshal([]byte(responseString), &responseData.Responses[0]); err != nil {
log.Error(ctx, "failed to unmarshal response from elasticsearch for data query", err)
if unMarshalErr := json.Unmarshal(responseString, &responseData.Responses[0]); unMarshalErr != nil {
log.Error(ctx, "failed to unmarshal response from elasticsearch for data query", unMarshalErr)
http.Error(w, "Failed to process data query", http.StatusInternalServerError)
return
}
Expand All @@ -75,6 +75,8 @@ func DataLookupHandlerFunc(elasticSearchClient ElasticSearcher) http.HandlerFunc
}

w.Header().Set("Content-Type", "application/json;charset=utf-8")
w.Write(dataWithResponse)
if _, err := w.Write(dataWithResponse); err != nil {
log.Error(ctx, "error occured while writing response data", err)
}
}
}
1 change: 0 additions & 1 deletion api/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

func TestDataLookupHandlerFunc(t *testing.T) {

Convey("Should return InternalError for invalid template", t, func() {
setupDataTestTemplates("dummy{{.Moo}}")
esMock := &ElasticSearcherMock{
Expand Down
64 changes: 0 additions & 64 deletions api/health.go

This file was deleted.

67 changes: 2 additions & 65 deletions api/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions api/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ import (
"github.com/pkg/errors"
)

const defaultContentTypes string = "bulletin," +
"article," +
const defaultContentTypes string = "article," +
"article_download," +
"bulletin," +
"compendium_landing_page," +
"reference_tables," +
"compendium_chapter," +
"compendium_data," +
"dataset," +
"dataset_landing_page," +
"product_page," +
"reference_tables," +
"release," +
"static_adhoc," +
"static_article," +
"static_foi," +
Expand All @@ -28,7 +33,8 @@ const defaultContentTypes string = "bulletin," +
"static_methodology_download," +
"static_page," +
"static_qmi," +
"timeseries"
"timeseries," +
"timeseries_dataset"

var serverErrorMessage = "internal server error"

Expand Down Expand Up @@ -117,7 +123,7 @@ func SearchHandlerFunc(queryBuilder QueryBuilder, elasticSearchClient ElasticSea
return
}

if !json.Valid([]byte(responseData)) {
if !json.Valid(responseData) {
log.Error(ctx, "elastic search returned invalid JSON for search query", errors.New("elastic search returned invalid JSON for search query"))
http.Error(w, "Failed to process search query", http.StatusInternalServerError)
return
Expand All @@ -139,7 +145,6 @@ func SearchHandlerFunc(queryBuilder QueryBuilder, elasticSearchClient ElasticSea
http.Error(w, "Failed to write http response", http.StatusInternalServerError)
return
}

}
}

Expand Down
1 change: 0 additions & 1 deletion api/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const validESResponse string = `{"raw":"response"}`
const validTransformedResponse string = `{"transformed":"response"}`

func TestSearchHandlerFunc(t *testing.T) {

Convey("Should return BadRequest for invalid limit parameter", t, func() {
qbMock := newQueryBuilderMock(nil, nil)
esMock := newElasticSearcherMock(nil, nil)
Expand Down
6 changes: 4 additions & 2 deletions api/timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ func TimeseriesLookupHandlerFunc(elasticSearchClient ElasticSearcher) http.Handl
return
}

if !json.Valid([]byte(responseData)) {
if !json.Valid(responseData) {
log.Error(ctx, "elastic search returned invalid JSON for timeseries query", errors.New("elastic search returned invalid JSON for timeseries query"))
http.Error(w, "Failed to process timeseries query", http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json;charset=utf-8")
w.Write(responseData)
if _, err := w.Write(responseData); err != nil {
log.Error(ctx, "error occured while writing response data", err)
}
}
}
Loading

0 comments on commit d74fea8

Please sign in to comment.