diff --git a/Makefile b/Makefile index 46173cf..fb55df4 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ -VPKG=dynatron.me/x/stillbox/pkg/gordio/version +VPKG=dynatron.me/x/stillbox/internal/version VER!=git describe --tags --always --dirty BUILDDATE!=date '+%Y-%m-%e' LDFLAGS=-ldflags="-X '${VPKG}.Version=${VER}' -X '${VPKG}.Built=${BUILDDATE}'" + all: checkcalls go build -o gordio ${LDFLAGS} ./cmd/gordio/ - go build -o calls ./cmd/calls/ + go build -o calls ${LDFLAGS} ./cmd/calls/ clean: rm -rf client/calls/ && mkdir client/calls && touch client/calls/.gitkeep diff --git a/cmd/calls/main.go b/cmd/calls/main.go index b2bd07c..5b01d45 100644 --- a/cmd/calls/main.go +++ b/cmd/calls/main.go @@ -13,12 +13,17 @@ import ( "strings" "time" + "dynatron.me/x/stillbox/internal/version" "dynatron.me/x/stillbox/pkg/pb" "github.com/gorilla/websocket" "google.golang.org/protobuf/proto" ) +const ( + AppName = "calls-tui" +) + var ( addr = flag.String("addr", "localhost:8080", "http service address") username = flag.String("user", "", "username") @@ -41,7 +46,8 @@ func main() { if err != nil { log.Fatal(err) } - loginReq.Header.Add("Content-Type", "application/x-www-form-urlencoded") + loginReq.Header.Set("Content-Type", "application/x-www-form-urlencoded") + version.UserAgent(loginReq.Header, AppName) jar, err := cookiejar.New(nil) if err != nil { @@ -74,7 +80,9 @@ func main() { HandshakeTimeout: 45 * time.Second, Jar: jar, } - c, _, err := dialer.Dial(u.String(), nil) + wsHdr := make(http.Header) + version.UserAgent(wsHdr, AppName) + c, _, err := dialer.Dial(u.String(), wsHdr) if err != nil { log.Fatal("dial:", err) } diff --git a/cmd/gordio/main.go b/cmd/gordio/main.go index 207c6b1..b1c0265 100644 --- a/cmd/gordio/main.go +++ b/cmd/gordio/main.go @@ -10,7 +10,7 @@ import ( "dynatron.me/x/stillbox/pkg/gordio" "dynatron.me/x/stillbox/pkg/gordio/admin" "dynatron.me/x/stillbox/pkg/gordio/config" - "dynatron.me/x/stillbox/pkg/gordio/version" + "dynatron.me/x/stillbox/internal/version" "github.com/spf13/cobra" ) diff --git a/pkg/gordio/version/version.go b/internal/version/version.go similarity index 59% rename from pkg/gordio/version/version.go rename to internal/version/version.go index cbd6533..cb680aa 100644 --- a/pkg/gordio/version/version.go +++ b/internal/version/version.go @@ -2,6 +2,7 @@ package version import ( "fmt" + "net/http" "runtime" ) @@ -15,3 +16,7 @@ func String() string { return fmt.Sprintf("gordio %s\nbuilt %s for %s-%s\n", Version, Built, runtime.GOOS, runtime.GOARCH) } + +func UserAgent(hdr http.Header, app string) { + hdr.Set("User-Agent", fmt.Sprintf("stillbox %s/%s (%s/%s)", app, Version, runtime.GOOS, runtime.GOARCH)) +} diff --git a/pkg/gordio/nexus/client.go b/pkg/gordio/nexus/client.go index 63e1e18..475a72b 100644 --- a/pkg/gordio/nexus/client.go +++ b/pkg/gordio/nexus/client.go @@ -9,7 +9,7 @@ import ( "dynatron.me/x/stillbox/pkg/calls" "dynatron.me/x/stillbox/pkg/gordio/database" - "dynatron.me/x/stillbox/pkg/gordio/version" + "dynatron.me/x/stillbox/internal/version" "dynatron.me/x/stillbox/pkg/pb" "github.com/rs/zerolog/log"