Skip to content

Commit

Permalink
Merge tag 'v7.1.0' into ubuntu-ppa
Browse files Browse the repository at this point in the history
7.1.0

* Allow the `Host` configuration directive and the `GEOIPUPDATE_HOST`
  environment variable to accept a value with the scheme set. If not set, it
  will continue to default to `https://`. Pull request by Gabe Cook. GitHub
  #310.
* Export `HTTPError` to enable fine-grained error handling for users of
  `github.com/maxmind/geoipupdate/client`. Pull request by Ryan Davis. GitHub
  #341.
  • Loading branch information
oschwald committed Nov 18, 2024
2 parents e3552e7 + 662daf8 commit 62bda6a
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 102 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: "Code scanning - action"

on:
push:
branches-ignore:
- 'dependabot/**'
pull_request:
schedule:
- cron: '0 11 * * 2'

permissions:
security-events: write # Used by this action.

jobs:
CodeQL-Build:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: latest
21 changes: 21 additions & 0 deletions .github/workflows/modver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: modver

on:
pull_request:

permissions:
contents: read # This gets granted by default, so keep granting it.
packages: read # This gets granted by default, so keep granting it.
pull-requests: write # Needed to comment on the PR.

jobs:
modver:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: bobg/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
pull_request_url: https://github.com/${{ github.repository }}/pull/${{ github.event.number }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.swp
/build
/dist
/cmd/geoipupdate/geoipupdate
/vendor
.idea
42 changes: 21 additions & 21 deletions .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ timeout = "10m"
[linters]
enable-all = true
disable = [
# The canonical form is not always the most common form for some headers
# and there is a small chance that switching existing strings could
# break something.
"canonicalheader",

"cyclop",
"dogsled",
"dupl",
Expand All @@ -17,8 +22,8 @@ disable = [
# that would need to be addressed.
"dupword",

# This doesn't seem to know about CTEs or DELETEs with RETURNING
"execinquery",
# We don't follow its policy about not defining dynamic errors.
"err113",

# We often don't initialize all of the struct fields. This is fine
# generally
Expand All @@ -41,9 +46,7 @@ disable = [
"gochecksumtype",

"gocognit",
"goerr113",
"godox",
"gomnd",

# This only "caught" one thing, and it seemed like a reasonable use
# of Han script. Generally, I don't think we want to prevent the use
Expand All @@ -65,6 +68,10 @@ disable = [
# what to allow.
"maintidx",

# Using a const for every number doesn't necessarily increase code clarity,
# and it would be a ton of work to move everything to that.
"mnd",

# Causes panics, e.g., when processing mmerrors
"musttag",

Expand Down Expand Up @@ -99,18 +106,6 @@ disable = [
# This would probably be good, but we would need to configure it.
"wsl",

# These are all deprecated
"deadcode",
"exhaustivestruct",
"golint",
"ifshort",
"interfacer",
"maligned",
"nosnakecase",
"scopelint",
"structcheck",
"varcheck",

# Require Go 1.22
"copyloopvar",
"intrange",
Expand Down Expand Up @@ -154,11 +149,6 @@ exclude-functions = [
'os.RemoveAll',
]

# Ignoring Close so that we don't have to have a bunch of
# `defer func() { _ = r.Close() }()` constructs when we
# don't actually care about the error.
ignore = "Close,fmt:.*"

[linters-settings.errorlint]
errorf = true
asserts = true
Expand Down Expand Up @@ -606,6 +596,16 @@ linters = [
]
path = "_test.go"

[[issues.exclude-rules]]
linters = [
"errcheck",
]
# There are many cases where we want to just close resources and ignore the
# error (e.g., for defer f.Close on a read). errcheck removed its built-in
# wildcard ignore. I tried listing all of the cases, but it was too many
# and some were very specific.
source = "\\.Close"

[[issues.exclude-rules]]
linters = [
"stylecheck",
Expand Down
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
project_name: 'geoipupdate'
version: 2
archives:
- id: 'archives-unix'
builds:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## 7.1.0 (2024-11-18)

* Allow the `Host` configuration directive and the `GEOIPUPDATE_HOST`
environment variable to accept a value with the scheme set. If not set, it
will continue to default to `https://`. Pull request by Gabe Cook. GitHub
#310.
* Export `HTTPError` to enable fine-grained error handling for users of
`github.com/maxmind/geoipupdate/client`. Pull request by Ryan Davis. GitHub
#341.

## 7.0.1 (2024-04-08)

* The 7.0.0 release was broken and has been retracted. This release updates the
Expand Down
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
// Client downloads GeoIP2 and GeoLite2 MMDB databases.
//
// After creation, it is valid for concurrent use.
//
//nolint:recvcheck // changing this would be a breaking change.
type Client struct {
accountID int
endpoint string
Expand Down
10 changes: 9 additions & 1 deletion client/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/maxmind/geoipupdate/v7/internal/vars"
)

// HTTPError is an error from performing an HTTP request and receiving a non-200 status code.
//
// See https://dev.maxmind.com/geoip/docs/web-services/responses/#errors for more details.
type HTTPError = internal.HTTPError

// DownloadResponse describes the result of a Download call.
type DownloadResponse struct {
// LastModified is the date that the database was last modified. It will
Expand Down Expand Up @@ -55,6 +60,9 @@ type DownloadResponse struct {
//
// If the current MD5 checksum matches what the server currently has, no
// download is performed.
//
// Returns an [HTTPError] if the server returns a non-200 status code. This
// can be used to identify problems with license.
func (c Client) Download(
ctx context.Context,
editionID,
Expand Down Expand Up @@ -125,7 +133,7 @@ func (c *Client) download(
// TODO(horgh): Should we fully consume the body?
//nolint:errcheck // we are already returning an error.
buf, _ := io.ReadAll(io.LimitReader(response.Body, 256))
httpErr := internal.HTTPError{
httpErr := HTTPError{
Body: string(buf),
StatusCode: response.StatusCode,
}
Expand Down
51 changes: 36 additions & 15 deletions client/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -37,7 +38,7 @@ func TestDownload(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(jsonData))
require.NoError(t, err)
assert.NoError(t, err)
})

tests := []struct {
Expand All @@ -61,18 +62,26 @@ func TestDownload(t *testing.T) {
}

err := tw.WriteHeader(header)
require.NoError(t, err)
if !assert.NoError(t, err) {
return
}
_, err = tw.Write([]byte(dbContent))
require.NoError(t, err)
if !assert.NoError(t, err) {
return
}

require.NoError(t, tw.Close())
require.NoError(t, gw.Close())
if !assert.NoError(t, tw.Close()) {
return
}
if !assert.NoError(t, gw.Close()) {
return
}

w.Header().Set("Content-Type", "application/gzip")
w.Header().Set("Content-Disposition", "attachment; filename=test.tar.gz")
w.Header().Set("Last-Modified", lastModified.Format(time.RFC1123))
_, err = io.Copy(w, &buf)
require.NoError(t, err)
assert.NoError(t, err)
})

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -128,7 +137,7 @@ func TestDownload(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(jsonData))
require.NoError(t, err)
assert.NoError(t, err)
}))
return server
},
Expand All @@ -145,13 +154,17 @@ func TestDownload(t *testing.T) {
var buf bytes.Buffer
gw := gzip.NewWriter(&buf)
tw := tar.NewWriter(gw)
require.NoError(t, tw.Close())
require.NoError(t, gw.Close())
if !assert.NoError(t, tw.Close()) {
return
}
if !assert.NoError(t, gw.Close()) {
return
}

w.Header().Set("Content-Type", "application/gzip")
w.Header().Set("Content-Disposition", "attachment; filename=test.tar.gz")
_, err := io.Copy(w, &buf)
require.NoError(t, err)
assert.NoError(t, err)
})

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -185,17 +198,25 @@ func TestDownload(t *testing.T) {
}

err := tw.WriteHeader(header)
require.NoError(t, err)
if !assert.NoError(t, err) {
return
}
_, err = tw.Write([]byte(dbContent))
require.NoError(t, err)
if !assert.NoError(t, err) {
return
}

require.NoError(t, tw.Close())
require.NoError(t, gw.Close())
if !assert.NoError(t, tw.Close()) {
return
}
if !assert.NoError(t, gw.Close()) {
return
}

w.Header().Set("Content-Type", "application/gzip")
w.Header().Set("Content-Disposition", "attachment; filename=test.tar.gz")
_, err = io.Copy(w, &buf)
require.NoError(t, err)
assert.NoError(t, err)
})

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
3 changes: 1 addition & 2 deletions client/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/url"
"strconv"

"github.com/maxmind/geoipupdate/v7/internal"
"github.com/maxmind/geoipupdate/v7/internal/vars"
)

Expand Down Expand Up @@ -51,7 +50,7 @@ func (c *Client) getMetadata(
}

if response.StatusCode != http.StatusOK {
httpErr := internal.HTTPError{
httpErr := HTTPError{
Body: string(responseBody),
StatusCode: response.StatusCode,
}
Expand Down
3 changes: 2 additions & 1 deletion client/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -32,7 +33,7 @@ func TestGetMetadata(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(jsonData))
require.NoError(t, err)
assert.NoError(t, err)
}))
return server
},
Expand Down
Loading

0 comments on commit 62bda6a

Please sign in to comment.