Skip to content

Commit 72b5304

Browse files
authored
feat: add a target URL to the welcome message (#13)
* feat: add a target URL to the welcome message (#13)
1 parent ec99e08 commit 72b5304

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
log.Fatalf("failed to init a query plan exporter: %v", err)
3030
}
3131

32-
fmt.Printf("Welcome to the query plan exporter. Target: %s.\n", *target)
32+
fmt.Println(generateWelcomeMessage(planner))
3333

3434
scannerCfg := &pgscanner.Config{
3535
AutoConfirm: *autoConfirm,
@@ -38,3 +38,7 @@ func main() {
3838
pgScanner := pgscanner.New(scannerCfg, os.Stdin, os.Stdout, planner)
3939
pgScanner.Run(ctx)
4040
}
41+
42+
func generateWelcomeMessage(planner pgscanner.PlanExporter) string {
43+
return fmt.Sprintf("Welcome to the query plan exporter.\nURL: %s", planner.Target())
44+
}

pgscanner/pgscanner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const confirmationResponse = "Y"
2222
// PlanExporter defines the interface to post query plans.
2323
type PlanExporter interface {
2424
Export(string) (string, error)
25+
Target() string
2526
}
2627

2728
// PgScanner provides a psql output scanner.

pgscanner/pgscanner_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ func (m Mock) Export(s string) (string, error) {
1515
return m.url, m.err
1616
}
1717

18+
func (m Mock) Target() string {
19+
return m.url
20+
}
21+
1822
func TestSuccessfulPlanPosting(t *testing.T) {
1923
buf := &bytes.Buffer{}
2024

visualizer/dalibo/dalibo.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/agneum/plan-exporter/client"
99
)
1010

11-
// visualizer constants
11+
// Visualizer constants.
1212
const (
1313
VisualizerType = "dalibo"
1414
defaultPostURL = "https://explain.dalibo.com/new"
@@ -40,3 +40,8 @@ func (d *Dalibo) Export(plan string) (string, error) {
4040

4141
return explainURL, nil
4242
}
43+
44+
// Target returns a post URL.
45+
func (d *Dalibo) Target() string {
46+
return d.postURL
47+
}

visualizer/depesz/depesz.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/agneum/plan-exporter/client"
99
)
1010

11-
// visualizer constants
11+
// Visualizer constants.
1212
const (
1313
VisualizerType = "depesz"
1414
defaultPostURL = "https://explain.depesz.com/"
@@ -40,3 +40,8 @@ func (d *Depesz) Export(plan string) (string, error) {
4040

4141
return explainURL, nil
4242
}
43+
44+
// Target returns a post URL.
45+
func (d *Depesz) Target() string {
46+
return d.postURL
47+
}

visualizer/tensor/tensor.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/agneum/plan-exporter/client"
99
)
1010

11-
// visualizer constants
11+
// Visualizer constants.
1212
const (
1313
VisualizerType = "tensor"
1414
defaultPostURL = "https://explain.tensor.ru/explain"
@@ -30,13 +30,18 @@ func New(postURL string) *Tensor {
3030
}
3131

3232
// Export posts plan to a visualizer and returns link to the visualization plan page.
33-
func (d *Tensor) Export(plan string) (string, error) {
33+
func (t *Tensor) Export(plan string) (string, error) {
3434
formVal := url.Values{planKey: []string{plan}}
3535

36-
explainURL, err := client.MakeRequest(d.postURL, formVal)
36+
explainURL, err := client.MakeRequest(t.postURL, formVal)
3737
if err != nil {
3838
return "", fmt.Errorf("failed to make a request: %w", err)
3939
}
4040

4141
return explainURL, nil
4242
}
43+
44+
// Target returns a post URL.
45+
func (t *Tensor) Target() string {
46+
return t.postURL
47+
}

0 commit comments

Comments
 (0)