Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch grpc url using about api #28

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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