User agent

This commit is contained in:
Daniel 2024-10-21 22:37:44 -04:00
parent d9aaac3b0c
commit 334c509f8b
5 changed files with 20 additions and 6 deletions

View file

@ -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

View file

@ -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)
}

View file

@ -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"
)

View file

@ -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))
}

View file

@ -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"