Skip to content

Commit

Permalink
feat: Add version to user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniCodeMonkey committed Jan 14, 2022
1 parent 911461e commit 7ab98f9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ builds:
- linux
- windows
- darwin
ldflags:
- -s -w -X github.com/geocodio/geocodio-cli/release.version={{.Version}} -X github.com/geocodio/geocodio-cli/release.commit={{.Commit}} -X github.com/geocodio/geocodio-cli/release.date={{.Date}}
archives:
- replacements:
darwin: Darwin
Expand Down
9 changes: 7 additions & 2 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"bytes"
"fmt"
"github.com/geocodio/geocodio-cli/release"
"github.com/urfave/cli/v2"
"io"
"io/ioutil"
Expand Down Expand Up @@ -30,7 +31,7 @@ func Request(method string, path string, c *cli.Context) ([]byte, error) {
return nil, err
}

req.Header.Set("User-Agent", fmt.Sprintf("geocodio-cli"))
req.Header.Set("User-Agent", buildUserAgent())

res, getErr := client.Do(req)
if getErr != nil {
Expand Down Expand Up @@ -94,7 +95,7 @@ func Upload(file *os.File, direction string, format string, fields string, c *cl
}

req.Header.Add("Content-Type", writer.FormDataContentType())
req.Header.Set("User-Agent", fmt.Sprintf("geocodio-cli"))
req.Header.Set("User-Agent", buildUserAgent())

res, getErr := client.Do(req)
if getErr != nil {
Expand All @@ -112,3 +113,7 @@ func Upload(file *os.File, direction string, format string, fields string, c *cl

return responseBody, nil
}

func buildUserAgent() string {
return fmt.Sprintf("geocodio-cli v%s", release.Version())
}
7 changes: 3 additions & 4 deletions geocodio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ package main
import (
"github.com/geocodio/geocodio-cli/create"
"github.com/geocodio/geocodio-cli/list"
"github.com/geocodio/geocodio-cli/release"
"github.com/geocodio/geocodio-cli/remove"
"github.com/geocodio/geocodio-cli/status"
"github.com/urfave/cli/v2"
"log"
"os"
)

var version string

func main() {
app := cli.NewApp()
app.Name = "Geocodio"
app.Usage = "Geocode lists using the Geocodio API " + version
app.Version = version
app.Usage = "Geocode lists using the Geocodio API"
app.Version = release.Version()
app.EnableBashCompletion = true
app.Flags = []cli.Flag{
&cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ go 1.17

require (
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.13.0
github.com/olekukonko/tablewriter v0.0.5
github.com/urfave/cli/v2 v2.3.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
Expand Down
19 changes: 19 additions & 0 deletions release/release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package release

var (
version = "dev"
commit = "none"
date = "unknown"
)

func Version() string {
return version
}

func Commit() string {
return commit
}

func Date() string {
return date
}

0 comments on commit 7ab98f9

Please sign in to comment.