diff --git a/cmd/client.go b/cmd/client.go index 543cbaf..2675796 100644 --- a/cmd/client.go +++ b/cmd/client.go @@ -20,9 +20,8 @@ import ( "io" "net/http" "net/url" - "time" - "pb/pkg/config" + "time" ) type HTTPClient struct { diff --git a/cmd/filterList.go b/cmd/filterList.go index b23f667..7563e97 100644 --- a/cmd/filterList.go +++ b/cmd/filterList.go @@ -18,11 +18,10 @@ package cmd import ( "fmt" "os" + "pb/pkg/model" "strings" "time" - "pb/pkg/model" - "github.com/spf13/cobra" ) @@ -32,10 +31,10 @@ var FilterList = &cobra.Command{ Short: "List of saved filter for a stream", Long: "\nShow a list of saved filter for a stream ", PreRunE: PreRunDefaultProfile, - Run: func(command *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { client := DefaultClient() - p := model.UiApp() + p := model.UIApp() _, err := p.Run() if err != nil { os.Exit(1) @@ -46,16 +45,16 @@ var FilterList = &cobra.Command{ if a.Stream() != "" { filterToPbQuery(a.Stream(), a.StartTime(), a.EndTime()) } - if d.FilterId() != "" { - deleteFilter(&client, d.FilterId()) + if d.FilterID() != "" { + deleteFilter(&client, d.FilterID()) } }, } // Delete a saved filter from the list of filter func deleteFilter(client *HTTPClient, filterID string) { - deleteUrl := `filters/filter/` + filterID - req, err := client.NewRequest("DELETE", deleteUrl, nil) + deleteURL := `filters/filter/` + filterID + req, err := client.NewRequest("DELETE", deleteURL, nil) if err != nil { fmt.Println("Error deleting the filter") } diff --git a/cmd/pre.go b/cmd/pre.go index d3423d6..d6bac82 100644 --- a/cmd/pre.go +++ b/cmd/pre.go @@ -19,7 +19,6 @@ package cmd import ( "errors" "os" - "pb/pkg/config" "github.com/spf13/cobra" diff --git a/cmd/profile.go b/cmd/profile.go index b97bfd5..10e2d03 100644 --- a/cmd/profile.go +++ b/cmd/profile.go @@ -20,7 +20,6 @@ import ( "fmt" "net/url" "os" - "pb/pkg/config" "pb/pkg/model/credential" "pb/pkg/model/defaultprofile" diff --git a/cmd/query.go b/cmd/query.go index 9e20e6f..245768c 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -20,13 +20,13 @@ import ( "fmt" "io" "os" + "pb/pkg/config" "strings" "time" - "pb/pkg/config" // "pb/pkg/model" - //! This dependancy is required by the interactive flag Do not remove + //! This dependency is required by the interactive flag Do not remove // tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" ) @@ -183,32 +183,32 @@ func fetchData(client *HTTPClient, query string, startTime string, endTime strin } // Returns start and end time for query in RFC3339 format -func parseTime(start, end string) (time.Time, time.Time, error) { - if start == defaultStart && end == defaultEnd { - return time.Now().Add(-1 * time.Minute), time.Now(), nil - } - - startTime, err := time.Parse(time.RFC3339, start) - if err != nil { - // try parsing as duration - duration, err := time.ParseDuration(start) - if err != nil { - return time.Time{}, time.Time{}, err - } - startTime = time.Now().Add(-1 * duration) - } - - endTime, err := time.Parse(time.RFC3339, end) - if err != nil { - if end == "now" { - endTime = time.Now() - } else { - return time.Time{}, time.Time{}, err - } - } - - return startTime, endTime, nil -} +// func parseTime(start, end string) (time.Time, time.Time, error) { +// if start == defaultStart && end == defaultEnd { +// return time.Now().Add(-1 * time.Minute), time.Now(), nil +// } + +// startTime, err := time.Parse(time.RFC3339, start) +// if err != nil { +// // try parsing as duration +// duration, err := time.ParseDuration(start) +// if err != nil { +// return time.Time{}, time.Time{}, err +// } +// startTime = time.Now().Add(-1 * duration) +// } + +// endTime, err := time.Parse(time.RFC3339, end) +// if err != nil { +// if end == "now" { +// endTime = time.Now() +// } else { +// return time.Time{}, time.Time{}, err +// } +// } + +// return startTime, endTime, nil +// } // create a request body for saving filter without time_filter func createFilter(query string, filterName string) (err error) { diff --git a/cmd/role.go b/cmd/role.go index 6b8d9d9..7bcd927 100644 --- a/cmd/role.go +++ b/cmd/role.go @@ -21,11 +21,10 @@ import ( "fmt" "io" "os" + "pb/pkg/model/role" "strings" "sync" - "pb/pkg/model/role" - tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/spf13/cobra" diff --git a/cmd/tail.go b/cmd/tail.go index a71c71e..bf6725a 100644 --- a/cmd/tail.go +++ b/cmd/tail.go @@ -22,7 +22,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "pb/pkg/config" "github.com/apache/arrow/go/v13/arrow/array" diff --git a/main.go b/main.go index ed45009..e356167 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,6 @@ package main import ( "errors" "os" - "pb/cmd" "pb/pkg/config" diff --git a/pkg/model/credential/credential.go b/pkg/model/credential/credential.go index 66a3eaf..d906d7b 100644 --- a/pkg/model/credential/credential.go +++ b/pkg/model/credential/credential.go @@ -17,9 +17,8 @@ package credential import ( - "strings" - "pb/pkg/model/button" + "strings" "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" diff --git a/pkg/model/defaultprofile/profile.go b/pkg/model/defaultprofile/profile.go index 2f8e168..9077054 100644 --- a/pkg/model/defaultprofile/profile.go +++ b/pkg/model/defaultprofile/profile.go @@ -18,7 +18,6 @@ package defaultprofile import ( "fmt" "io" - "pb/pkg/config" "github.com/charmbracelet/bubbles/list" diff --git a/pkg/model/query.go b/pkg/model/query.go index 8e7ad99..5a25444 100644 --- a/pkg/model/query.go +++ b/pkg/model/query.go @@ -23,13 +23,12 @@ import ( "math" "net/http" "os" + "pb/pkg/config" + "pb/pkg/iterator" "strings" "sync" "time" - "pb/pkg/config" - "pb/pkg/iterator" - "github.com/charmbracelet/bubbles/help" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/textarea" diff --git a/pkg/model/role/role.go b/pkg/model/role/role.go index 9202fba..05783f1 100644 --- a/pkg/model/role/role.go +++ b/pkg/model/role/role.go @@ -18,10 +18,9 @@ package role import ( "fmt" - "strings" - "pb/pkg/model/button" "pb/pkg/model/selection" + "strings" "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index 88e1ae1..9660881 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -12,6 +12,7 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . + package model import ( @@ -19,11 +20,10 @@ import ( "fmt" "io" "net/http" + "pb/pkg/config" "strings" "time" - "pb/pkg/config" - "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" @@ -39,14 +39,15 @@ var docStyle = lipgloss.NewStyle().Margin(1, 2) // FilterDetails represents the structure of filter data type FilterDetails struct { - FilterId string `json:"filter_id"` + FilterID string `json:"filter_id"` FilterName string `json:"filter_name"` StreamName string `json:"stream_name"` QueryField map[string]interface{} `json:"query"` TimeFilter map[string]interface{} `json:"time_filter"` } -type item struct { +// Item represents the structure of the filter item +type Item struct { id, title, stream, desc, from, to string } @@ -64,7 +65,7 @@ func (d itemDelegate) Height() int { return 4 } func (d itemDelegate) Spacing() int { return 1 } func (d itemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil } func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) { - i, ok := listItem.(item) + i, ok := listItem.(Item) if !ok { return } @@ -118,24 +119,24 @@ func (d itemDelegate) FullHelp() [][]key.Binding { } var ( - selectedFilterApply item - selectedFilterDelete item + selectedFilterApply Item + selectedFilterDelete Item ) -func (i item) Title() string { return fmt.Sprintf("Filter:%s, Query:%s", i.title, i.desc) } +func (i Item) Title() string { return fmt.Sprintf("Filter:%s, Query:%s", i.title, i.desc) } -func (i item) Description() string { +func (i Item) Description() string { if i.to == "" || i.from == "" { return "" } return fmt.Sprintf("From:%s To:%s", i.from, i.to) } -func (i item) FilterValue() string { return i.title } -func (i item) FilterId() string { return i.id } -func (i item) Stream() string { return i.desc } -func (i item) StartTime() string { return i.from } -func (i item) EndTime() string { return i.to } +func (i Item) FilterValue() string { return i.title } +func (i Item) FilterID() string { return i.id } +func (i Item) Stream() string { return i.desc } +func (i Item) StartTime() string { return i.from } +func (i Item) EndTime() string { return i.to } type modelFilter struct { list list.Model @@ -152,11 +153,11 @@ func (m modelFilter) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit } if msg.String() == "a" || msg.Type == tea.KeyEnter { - selectedFilterApply = m.list.SelectedItem().(item) + selectedFilterApply = m.list.SelectedItem().(Item) return m, tea.Quit } if msg.String() == "d" { - selectedFilterDelete = m.list.SelectedItem().(item) + selectedFilterDelete = m.list.SelectedItem().(Item) return m, tea.Quit } @@ -174,8 +175,8 @@ func (m modelFilter) View() string { return docStyle.Render(m.list.View()) } -// Interactive list for the user to display all the available filters (only saved SQL filters ) -func UiApp() *tea.Program { +// UIApp lists interactive list for the user to display all the available filters (only saved SQL filters ) +func UIApp() *tea.Program { userConfig, err := config.ReadConfigFromFile() if err != nil { fmt.Println("Error reading Default Profile") @@ -223,12 +224,12 @@ func fetchFilters(client *http.Client, profile *config.Profile) []list.Item { var filters []FilterDetails err = json.Unmarshal(body, &filters) if err != nil { - fmt.Println("Error unmarshaling response:", err) + fmt.Println("Error unmarshalling response:", err) return nil } var userFilters []list.Item for _, filter := range filters { - var userFilter item + var userFilter Item queryBytes, _ := json.Marshal(filter.QueryField["filter_query"]) // Extract "from" and "to" from time_filter @@ -241,8 +242,8 @@ func fetchFilters(client *http.Client, profile *config.Profile) []list.Item { } // filtering only SQL type filters Filter_name is tile and Stream Name is desc if string(queryBytes) != "null" { - userFilter = item{ - id: filter.FilterId, + userFilter = Item{ + id: filter.FilterID, title: filter.FilterName, stream: filter.StreamName, desc: string(queryBytes), @@ -255,12 +256,12 @@ func fetchFilters(client *http.Client, profile *config.Profile) []list.Item { return userFilters } -// returns the selected filter by user in the iteractive list -func FilterToApply() item { +// FilterToApply returns the selected filter by user in the interactive list to apply +func FilterToApply() Item { return selectedFilterApply } -// returns the selected filter by user in the iteractive list -func FilterToDelete() item { +// FilterToDelete returns the selected filter by user in the interactive list to delete +func FilterToDelete() Item { return selectedFilterDelete } diff --git a/pkg/model/timeinput.go b/pkg/model/timeinput.go index 4627fc7..7144ba7 100644 --- a/pkg/model/timeinput.go +++ b/pkg/model/timeinput.go @@ -18,9 +18,8 @@ package model import ( "fmt" - "time" - "pb/pkg/model/datetime" + "time" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list"