Skip to content

Commit

Permalink
Merge pull request #40 from maxmind/greg/fixes
Browse files Browse the repository at this point in the history
Fix man formatting and stop vendoring our deps
  • Loading branch information
horgh authored Sep 11, 2019
2 parents 98bbeb0 + 9815fe7 commit ad21829
Show file tree
Hide file tree
Showing 89 changed files with 165 additions and 14,485 deletions.
35 changes: 35 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[run]
deadline = "10m"
tests = true

[linters]
disable-all = true
enable = [
"deadcode",
"depguard",
"errcheck",
"goconst",
"gocyclo",
"gocritic",
"gofmt",
"golint",
"gosec",
"gosimple",
"ineffassign",
"maligned",
"misspell",
"nakedret",
"staticcheck",
"structcheck",
"typecheck",
"unconvert",
"unparam",
"varcheck",
"vet",
"vetshadow",
]

# This goes off for MD5 usage, which we use heavily
[[issues.exclude-rules]]
text = "weak cryptographic primitive"
linters = ["gosec"]
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ matrix:
- go: "1.10.x"
- go: "1.11.x"
- go: "1.12.x"
- go: "1.13.x"

install:
- go get -t ./...
- "curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin"

script:
- go test -race
- golangci-lint run

script: go test -v ./...
4 changes: 2 additions & 2 deletions cmd/geoipupdate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Config struct {
}

// NewConfig parses the configuration file.
func NewConfig(
func NewConfig( // nolint: gocyclo
file,
databaseDirectory string,
) (*Config, error) {
Expand Down Expand Up @@ -195,7 +195,7 @@ func parseProxy(
return nil, errors.Wrap(err, "error parsing proxy URL")
}

if strings.Index(u.Host, ":") == -1 {
if !strings.Contains(u.Host, ":") {
u.Host += ":1080" // The 1080 default historically came from cURL.
}

Expand Down
10 changes: 3 additions & 7 deletions cmd/geoipupdate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func setup(
config *Config,
verbose bool,
) (*flock.Flock, error) {
if err := maybeSetProxy(config, verbose); err != nil {
return nil, err
}
maybeSetProxy(config, verbose)

if err := checkEnvironment(config); err != nil {
return nil, err
Expand Down Expand Up @@ -99,17 +97,15 @@ var client = &http.Client{}
func maybeSetProxy(
config *Config,
verbose bool,
) error {
) {
if config.Proxy == nil {
return nil
return
}

if verbose {
log.Printf("Using proxy: %s", config.Proxy)
}
http.DefaultTransport.(*http.Transport).Proxy = http.ProxyURL(config.Proxy)

return nil
}

func checkEnvironment(
Expand Down
2 changes: 1 addition & 1 deletion cmd/geoipupdate/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func TestUpdateEdition(t *testing.T) {
if test.DatabaseAfter != "" {
buf, err := ioutil.ReadFile(currentDatabasePath)
require.NoError(t, err, test.Description)
assert.Equal(t, string(test.DatabaseAfter), string(buf))
assert.Equal(t, test.DatabaseAfter, string(buf))
}

if !test.ExpectedTime.IsZero() {
Expand Down
106 changes: 65 additions & 41 deletions doc/GeoIP.conf.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,85 @@
# GeoIP.conf

## NAME
# NAME

GeoIP.conf - Configuration file for geoipupdate

## SYNOPSIS
# SYNOPSIS

This file allows you to configure your `geoipupdate` program to
download GeoIP2, GeoLite2, and GeoIP Legacy databases.

## DESCRIPTION
# DESCRIPTION

The file consists of one setting per line. Lines starting with `#`
are comments and will not be processed. All setting keywords are case
sensitive.

### Required settings:

* `EditionIDs` - List of database edition IDs. Edition IDs may consist
of letters, digits, and dashes (e.g., "GeoIP2-City", "106"). Note: this
was formerly called `ProductIds`.

### Optional settings:

* `AccountID` - Your MaxMind account ID. This was formerly known as
`UserId`.
* `DatabaseDirectory` - The directory to store the database files. If not
set, the default is DATADIR. This can be overridden at run time by the
`-d` command line argument.
* `Host` - The host name of the server to use. The default is
`updates.maxmind.com`.
* `Proxy` - The proxy host name or IP address. You may optionally specify
a port number, e.g., `127.0.0.1:8888`. If no port number is specified,
1080 will be used.
* `ProxyUserPassword` - The proxy user name and password, separated by a
colon. For instance, `username:password`.
* `PreserveFileTimes` - Whether to preserve modification times of files
downloaded from the server. This option is either `0` or `1`. The default
is `0`.
* `LicenseKey` - Your case-sensitive MaxMind license key.
* `LockFile` - The lock file to use. This ensures only one `geoipupdate`
process can run at a time. Note: Once created, this lockfile is not removed
from the filesystem. The default is `.geoipupdate.lock` under the
`DatabaseDirectory`.

### Deprecated settings:
## Required settings:

`EditionIDs`

: List of database edition IDs. Edition IDs may consist
of letters, digits, and dashes (e.g., "GeoIP2-City", "106"). Note: this
was formerly called `ProductIds`.

## Optional settings:

`AccountID`

: Your MaxMind account ID. This was formerly known as `UserId`.

`DatabaseDirectory`

: The directory to store the database files. If not set, the default is
DATADIR. This can be overridden at run time by the `-d` command line
argument.

`Host`

: The host name of the server to use. The default is `updates.maxmind.com`.

`Proxy`

: The proxy host name or IP address. You may optionally specify
a port number, e.g., `127.0.0.1:8888`. If no port number is specified,
1080 will be used.

`ProxyUserPassword`

: The proxy user name and password, separated by a colon. For instance,
`username:password`.

`PreserveFileTimes`

: Whether to preserve modification times of files downloaded from the
server. This option is either `0` or `1`. The default is `0`.

`LicenseKey`

: Your case-sensitive MaxMind license key.

`LockFile`

: The lock file to use. This ensures only one `geoipupdate` process can run
at a time. Note: Once created, this lockfile is not removed from the
filesystem. The default is `.geoipupdate.lock` under the
`DatabaseDirectory`.

## Deprecated settings:

The following are deprecated and will be ignored if present:

* `Protocol`
* `SkipPeerVerification`
* `SkipHostnameVerification`
`Protocol`

`SkipPeerVerification`

`SkipHostnameVerification`

# FILES

## FILES
`GeoIP.conf`

* `GeoIP.conf` - Default `geoipupdate` configuration file.
: Default `geoipupdate` configuration file.

## SEE ALSO
# SEE ALSO

`geoipupdate`(1)
79 changes: 44 additions & 35 deletions doc/geoipupdate.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# GEOIPUPDATE

## NAME
# NAME

geoipupdate - GeoIP2, GeoLite2, and GeoIP Legacy Update Program

## SYNOPSIS
# SYNOPSIS

```
geoipupdate [-Vvh] [-f CONFIG_FILE] [-d TARGET_DIRECTORY]
```
geoipupdate [-Vvh] [-f CONFIG_FILE] [-d TARGET_DIRECTORY]

## DESCRIPTION
# DESCRIPTION

`geoipupdate` automatically updates GeoIP2, GeoLite2, and GeoIP Legacy
databases. The program connects to the MaxMind GeoIP Update server to
Expand All @@ -20,72 +16,85 @@ download and install it.
If you are using a firewall, you must have the DNS and HTTPS ports
open.

## OPTIONS
# OPTIONS


`-d`, `--database-directory`

: Install databases to a custom directory. This is optional. If provided, it
overrides any `DatabaseDirectory` set in the configuration file.

`-f`, `--config-file`

: The configuration file to use. See `GeoIP.conf` and its documentation for
more information. This is optional. It defaults to CONFFILE.

`-h`, `--help`

: Display help and exit.

`--stack-trace`

: Show a stack trace on any error message. This is primarily useful for
debugging.

`-V`, `--version`

: Display version information and exit.

`-v`, `--verbose`

* `-d`, `--database-directory` - Install databases to a custom directory.
This is optional. If provided, it overrides any `DatabaseDirectory` set
in the configuration file.
* `-f`, `--config-file` - The configuration file to use. See GeoIP.conf and
its documentation for more information. This is optional. It defaults to
CONFFILE.
* `-h`, `--help` - Display help and exit.
* `--stack-trace` - Show a stack trace on any error message. This is
primarily useful for debugging.
* `-V`, `--version` - Display version information and exit.
* `-v`, `--verbose` - Enable verbose mode. Prints out the steps that
`geoipupdate` takes.
: Enable verbose mode. Prints out the steps that `geoipupdate` takes.

## USAGE
# USAGE

Typically you should run `geoipupdate` weekly. On most Unix-like systems,
this can be achieved by using cron. Below is a sample crontab file that
runs `geoipupdate` on each Wednesday at noon:

```
# top of crontab
# top of crontab

[email protected]
[email protected]

0 12 * * 3 geoipupdate
0 12 * * 3 geoipupdate

# end of crontab
# end of crontab

```

To use with a proxy server, update your `GeoIP.conf` file as specified
in the `GeoIP.conf` man page or set the `http_proxy` environment
variable.

## RETURN CODES
# RETURN CODES

`geoipupdate` returns 0 on success and 1 on error.

## FILES
# FILES

* `GeoIP.conf` - Configuration file for GeoIP Update. See the
`GeoIP.conf` documentation for more information.

## AUTHOR
# AUTHOR

Written by William Storey.

## REPORTING BUGS
# REPORTING BUGS

Report bugs to [[email protected]](mailto:[email protected]).

## COPYRIGHT
# COPYRIGHT

This software is Copyright (c) 2018-2019 by MaxMind, Inc.

This is free software, licensed under the Apache License, Version 2.0 or
the MIT License, at your option.

## MORE INFORMATION
# MORE INFORMATION

Visit [our website](https://www.maxmind.com/en/geoip2-services-and-databases)
to learn more about the GeoIP2 and GeoIP Legacy databases or to sign up
for a subscription.

## SEE ALSO
# SEE ALSO

`GeoIP.conf`(5)
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ require (
github.com/kr/pretty v0.1.0 // indirect
github.com/pkg/errors v0.8.1
github.com/spf13/pflag v1.0.3
github.com/stretchr/testify v1.3.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
github.com/stretchr/testify v1.4.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
11 changes: 7 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Loading

0 comments on commit ad21829

Please sign in to comment.