diff --git a/ui/table.go b/ui/table.go index 2f0aca5..2051799 100644 --- a/ui/table.go +++ b/ui/table.go @@ -40,18 +40,18 @@ func (t *table) SetTableCells(g *Gui, title string) { } func (t *table) AddTableHeader(cellTxt string) { - t.SetCell(0, 0, t.SetTableCell(cellTxt, 1, tcell.ColorIndianRed, false)) - t.SetCell(0, 1, t.SetTableCell("Key", 3, tcell.ColorIndianRed, false)) - t.SetCell(0, 2, t.SetTableCell("Value", 3, tcell.ColorIndianRed, false)) + t.SetCell(0, 0, SetTableCell(cellTxt, 1, tcell.ColorIndianRed, false)) + t.SetCell(0, 1, SetTableCell("Key", 3, tcell.ColorIndianRed, false)) + t.SetCell(0, 2, SetTableCell("Value", 3, tcell.ColorIndianRed, false)) } func (t *table) AddParamsRow(idx int) { - t.SetCell(idx, 0, t.SetTableCell(fmt.Sprint(idx), 1, tcell.ColorWhite, false)) - t.SetCell(idx, 1, t.SetTableCell("", 3, tcell.ColorWhite, true)) - t.SetCell(idx, 2, t.SetTableCell("", 3, tcell.ColorWhite, true)) + t.SetCell(idx, 0, SetTableCell(fmt.Sprint(idx), 1, tcell.ColorWhite, false)) + t.SetCell(idx, 1, SetTableCell("", 3, tcell.ColorWhite, true)) + t.SetCell(idx, 2, SetTableCell("", 3, tcell.ColorWhite, true)) } -func (t *table) SetTableCell(title string, width int, color tcell.Color, selectable bool) *tview.TableCell { +func SetTableCell(title string, width int, color tcell.Color, selectable bool) *tview.TableCell { tcell := tview.NewTableCell(title) tcell.SetExpansion(width) tcell.SetAlign(tview.AlignCenter) diff --git a/ui/ui.go b/ui/ui.go index 988d593..2bc2fcf 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -5,7 +5,6 @@ import ( "io" "log" "net/http" - "net/url" "os" "strings" @@ -24,12 +23,6 @@ type Gui struct { NavTextView *navigate } -type Param struct { - Key string - Value string -} -type Params []Param - func New() *Gui { g := &Gui{ App: tview.NewApplication(), @@ -48,7 +41,7 @@ func (g *Gui) GetRequestUrl() string { field := g.UrlField urlText := field.GetText() params := g.ParamsTable.GetParams() - query := g.GetParamsText(params) + query := params.GetParamsText() return urlText + query } @@ -56,7 +49,7 @@ func (g *Gui) GetRequestUrl() string { func (g *Gui) HttpRequest(url string) *http.Response { bodyParams := g.BodyTable.GetParams() - value := g.GetBodyParamsText(bodyParams) + value := bodyParams.GetBodyParamsText() method := g.HTTPTextView.GetText(true) req, _ := http.NewRequest(method, url, strings.NewReader(value)) @@ -257,36 +250,3 @@ func (g *Gui) Modal(p tview.Primitive, width, height int) tview.Primitive { return grid } - -func (g *Gui) GetParamsText(params Params) string { - var query string - for i, v := range params { - if v.Key == "" || v.Value == "" { - continue - } - if i == 0 { - query += "?" - } else { - query += "&" - } - query += fmt.Sprintf("%s=%s", v.Key, v.Value) - } - - return query -} - -func (g *Gui) GetBodyParamsText(params Params) string { - val := url.Values{} - for i, v := range params { - if v.Key == "" || v.Value == "" { - continue - } - if i == 0 { - val.Set(v.Key, v.Value) - } else { - val.Add(v.Key, v.Value) - } - } - - return val.Encode() -}