User agent
This commit is contained in:
parent
d9aaac3b0c
commit
334c509f8b
5 changed files with 20 additions and 6 deletions
5
Makefile
5
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
|
VER!=git describe --tags --always --dirty
|
||||||
BUILDDATE!=date '+%Y-%m-%e'
|
BUILDDATE!=date '+%Y-%m-%e'
|
||||||
LDFLAGS=-ldflags="-X '${VPKG}.Version=${VER}' -X '${VPKG}.Built=${BUILDDATE}'"
|
LDFLAGS=-ldflags="-X '${VPKG}.Version=${VER}' -X '${VPKG}.Built=${BUILDDATE}'"
|
||||||
|
|
||||||
all: checkcalls
|
all: checkcalls
|
||||||
go build -o gordio ${LDFLAGS} ./cmd/gordio/
|
go build -o gordio ${LDFLAGS} ./cmd/gordio/
|
||||||
go build -o calls ./cmd/calls/
|
go build -o calls ${LDFLAGS} ./cmd/calls/
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf client/calls/ && mkdir client/calls && touch client/calls/.gitkeep
|
rm -rf client/calls/ && mkdir client/calls && touch client/calls/.gitkeep
|
||||||
|
|
|
@ -13,12 +13,17 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"dynatron.me/x/stillbox/internal/version"
|
||||||
"dynatron.me/x/stillbox/pkg/pb"
|
"dynatron.me/x/stillbox/pkg/pb"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
AppName = "calls-tui"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
addr = flag.String("addr", "localhost:8080", "http service address")
|
addr = flag.String("addr", "localhost:8080", "http service address")
|
||||||
username = flag.String("user", "", "username")
|
username = flag.String("user", "", "username")
|
||||||
|
@ -41,7 +46,8 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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)
|
jar, err := cookiejar.New(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,7 +80,9 @@ func main() {
|
||||||
HandshakeTimeout: 45 * time.Second,
|
HandshakeTimeout: 45 * time.Second,
|
||||||
Jar: jar,
|
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 {
|
if err != nil {
|
||||||
log.Fatal("dial:", err)
|
log.Fatal("dial:", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"dynatron.me/x/stillbox/pkg/gordio"
|
"dynatron.me/x/stillbox/pkg/gordio"
|
||||||
"dynatron.me/x/stillbox/pkg/gordio/admin"
|
"dynatron.me/x/stillbox/pkg/gordio/admin"
|
||||||
"dynatron.me/x/stillbox/pkg/gordio/config"
|
"dynatron.me/x/stillbox/pkg/gordio/config"
|
||||||
"dynatron.me/x/stillbox/pkg/gordio/version"
|
"dynatron.me/x/stillbox/internal/version"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package version
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,3 +16,7 @@ func String() string {
|
||||||
return fmt.Sprintf("gordio %s\nbuilt %s for %s-%s\n",
|
return fmt.Sprintf("gordio %s\nbuilt %s for %s-%s\n",
|
||||||
Version, Built, runtime.GOOS, runtime.GOARCH)
|
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))
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"dynatron.me/x/stillbox/pkg/calls"
|
"dynatron.me/x/stillbox/pkg/calls"
|
||||||
"dynatron.me/x/stillbox/pkg/gordio/database"
|
"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"
|
"dynatron.me/x/stillbox/pkg/pb"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
Loading…
Reference in a new issue