Skip to content

Commit

Permalink
Fetch gRPC URL from the about API response (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueleo authored Oct 18, 2023
1 parent d81f21e commit cc60210
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type About struct {
Mode string `json:"mode"`
Staging string `json:"staging"`
Store string `json:"store"`
GrpcPort uint16 `json:"grpcPort"`
UpdateAvailable bool `json:"updateAvailable"`
Version string `json:"version"`
}
Expand Down
12 changes: 10 additions & 2 deletions cmd/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"

"pb/pkg/config"

"github.com/apache/arrow/go/v13/arrow/array"
Expand Down Expand Up @@ -52,7 +51,16 @@ func tail(profile config.Profile, stream string) error {
}{
Stream: stream,
})
client, err := flight.NewClientWithMiddleware("localhost:8001", nil, nil, grpc.WithTransportCredentials(insecure.NewCredentials()))

// get grpc url for this request
httpClient := DefaultClient()
about, err := FetchAbout(&httpClient)
if err != nil {
return err
}
url := profile.GrpcAddr(fmt.Sprint(about.GrpcPort))

client, err := flight.NewClientWithMiddleware(url, nil, nil, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return err
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package config

import (
"fmt"
"net"
"net/url"
"os"
path "path/filepath"

Expand Down Expand Up @@ -51,6 +53,11 @@ type Profile struct {
Password string
}

func (p *Profile) GrpcAddr(port string) string {
urlv, _ := url.Parse(p.URL)
return net.JoinHostPort(urlv.Hostname(), port)
}

// WriteConfigToFile writes the configuration to the config file
func WriteConfigToFile(config *Config) error {
tomlData, _ := toml.Marshal(config)
Expand Down

0 comments on commit cc60210

Please sign in to comment.