Skip to content

Fix lint #85

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
version: 2

linters:
disable-all: true
settings:
errcheck:
exclude-functions:
- io/ioutil.ReadFile
- io.Copy(*bytes.Buffer)
- io.Copy(os.Stdout)
- (io.Closer).Close
enable:
- typecheck
- goimports
- misspell
- govet
- revive
# - revive
- ineffassign
- gomodguard
- gofmt
- unused
- nilnesserr

linters-settings:
golint:
min-confidence: 0

govet:
enable:
- typecheck
misspell:
locale: US

Expand Down
7 changes: 4 additions & 3 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ func fetchData(client *internalHTTP.HTTPClient, query string, startTime, endTime
}
encodedResponse, _ := json.MarshalIndent(jsonResponse, "", " ")
fmt.Println(string(encodedResponse))
} else {
io.Copy(os.Stdout, resp.Body)

return nil
}
return nil
_, err = io.Copy(os.Stdout, resp.Body)
return err
}

// Returns start and end time for query in RFC3339 format
Expand Down
7 changes: 6 additions & 1 deletion cmd/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ func tail(profile config.Profile, stream string) error {
if err != nil {
return err
}

var buf bytes.Buffer
array.RecordToJSON(record, &buf)
err = array.RecordToJSON(record, &buf)
if err != nil {
return err
}

fmt.Println(buf.String())
}
}
Expand Down
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ var cli = &cobra.Command{
PersistentPreRunE: analytics.CheckAndCreateULID,
RunE: func(command *cobra.Command, _ []string) error {
if p, _ := command.Flags().GetBool(versionFlag); p {
pb.PrintVersion(Version, Commit)
return nil
err := pb.PrintVersion(Version, Commit)
return err
}
return errors.New("no command or flag supplied")
},
Expand Down Expand Up @@ -303,7 +303,12 @@ func main() {

// Set as command
pb.VersionCmd.Run = func(_ *cobra.Command, _ []string) {
pb.PrintVersion(Version, Commit)

err := pb.PrintVersion(Version, Commit)
if err != nil {
fmt.Printf("failed to write to file %v\n", err)
os.Exit(1)
}
}

cli.AddCommand(pb.VersionCmd)
Expand Down
9 changes: 8 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Profile struct {
Password string `json:"password,omitempty"`
}

// GrpcAddr gives the grpc address of the parseable server
func (p *Profile) GrpcAddr(port string) string {
urlv, _ := url.Parse(p.URL)
return net.JoinHostPort(urlv.Hostname(), port)
Expand All @@ -77,7 +78,12 @@ func WriteConfigToFile(config *Config) error {
fmt.Println("Error creating the file:", err)
return err
}
defer file.Close()

defer func() {
if err := file.Close(); err != nil {
fmt.Printf("Error while closing file: %v \n", err)
}
}()
// Write the data into the file
_, err = file.Write(tomlData)
if err != nil {
Expand Down Expand Up @@ -107,6 +113,7 @@ func ReadConfigFromFile() (config *Config, err error) {
return config, nil
}

// GetProfile retrurns the parseable profile by reading the config
func GetProfile() (Profile, error) {
conf, err := ReadConfigFromFile()
if os.IsNotExist(err) {
Expand Down
21 changes: 15 additions & 6 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ func Apply(h Helm, verbose bool) error {
settings.SetNamespace(h.Namespace)
settings.EnvVars()
// Add repository
repoAdd(h)

err := repoAdd(h)
if err != nil {
return err
}
// RepoUpdate()

// Locate chart path
cp, err := client.ChartPathOptions.LocateChart(fmt.Sprintf("%s/%s", h.RepoName, h.ChartName), settings)
cp, err := client.LocateChart(fmt.Sprintf("%s/%s", h.RepoName, h.ChartName), settings)
if err != nil {
return err
}
Expand Down Expand Up @@ -159,7 +161,11 @@ func repoAdd(h Helm) error {
locked, err := fileLock.TryLockContext(lockCtx, time.Second)

if err == nil && locked {
defer fileLock.Unlock()
defer func() {
if err := fileLock.Unlock(); err != nil {
fmt.Printf("Error while unlocking file %v", err)
}
}()
}

if err != nil {
Expand Down Expand Up @@ -313,12 +319,15 @@ func Upgrade(h Helm) error {
settings.SetNamespace(h.Namespace)
settings.EnvVars()
// Add repository
repoAdd(h)
err := repoAdd(h)
if err != nil {
return err
}

// RepoUpdate()

// Locate chart path
cp, err := client.ChartPathOptions.LocateChart(fmt.Sprintf("%s/%s", h.RepoName, h.ChartName), settings)
cp, err := client.LocateChart(fmt.Sprintf("%s/%s", h.RepoName, h.ChartName), settings)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import (
"time"
)

// HTTPClient can be used to make HTTP requests in an idiomatic way
type HTTPClient struct {
Client http.Client
Profile *config.Profile
}

// DefaultClient creates a HTTPClient with default parameters
func DefaultClient(profile *config.Profile) HTTPClient {
return HTTPClient{
Client: http.Client{
Expand Down
24 changes: 17 additions & 7 deletions pkg/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,14 @@ func promptNamespaceAndCredentials() (*ParseableInfo, error) {
// applyParseableSecret creates and applies the Kubernetes secret
func applyParseableSecret(ps *ParseableInfo, store ObjectStore, objectStoreConfig ObjectStoreConfig) error {
var secretManifest string
if store == LocalStore {
switch store {
case LocalStore:
secretManifest = getParseableSecretLocal(ps)
} else if store == S3Store {
case S3Store:
secretManifest = getParseableSecretS3(ps, objectStoreConfig)
} else if store == BlobStore {
case BlobStore:
secretManifest = getParseableSecretBlob(ps, objectStoreConfig)
} else if store == GcsStore {
case GcsStore:
secretManifest = getParseableSecretGcs(ps, objectStoreConfig)
}

Expand Down Expand Up @@ -867,7 +868,10 @@ func startPortForward(namespace, serviceName, remotePort, localPort string, verb
for i := 0; i < retries; i++ {
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%s", localPort))
if err == nil {
conn.Close() // Connection successful, break out of the loop
err := conn.Close() // Connection successful, break out of the loop
if err != nil {
return err
}
fmt.Println(common.Green + "Port-forwarding successfully established!")
time.Sleep(5 * time.Second) // some delay
return nil
Expand All @@ -876,7 +880,10 @@ func startPortForward(namespace, serviceName, remotePort, localPort string, verb
}

// If we reach here, port-forwarding failed
cmd.Process.Kill() // Stop the kubectl process
err := cmd.Process.Kill() // Stop the kubectl process
if err != nil {
return err
}
return fmt.Errorf(common.Red+"failed to establish port-forward connection to localhost:%s", localPort)
}

Expand All @@ -893,7 +900,10 @@ func openBrowser(url string) {
fmt.Printf("Please open the following URL manually: %s\n", url)
return
}
cmd.Start()
err := cmd.Start()
if err != nil {
log.Fatalf("could not be be able to start the command %v", err)
}
}

func updateInstallerConfigMap(entry common.InstallerEntry) error {
Expand Down
1 change: 1 addition & 0 deletions pkg/iterator/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

// Package iterator provides functions for iterating queries
package iterator

import (
Expand Down
44 changes: 34 additions & 10 deletions pkg/iterator/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestIteratorConstruct(t *testing.T) {
iter := NewQueryIterator(scenario.StartTime(), scenario.EndTime(), true, scenario.QueryRunnerFunc(), scenario.HasDataFunc())

currentWindow := iter.windows[0]
if !(currentWindow.time == scenario.StartTime()) {
if currentWindow.time != scenario.StartTime() {
t.Fatalf("window time does not match start, expected %s, actual %s", scenario.StartTime().String(), currentWindow.time.String())
}
}
Expand All @@ -98,7 +98,10 @@ func TestIteratorAscending(t *testing.T) {
scenario := DefaultTestScenario()
iter := NewQueryIterator(scenario.StartTime(), scenario.EndTime(), true, scenario.QueryRunnerFunc(), scenario.HasDataFunc())

iter.Next()
_, err := iter.Next()
if err != nil {
t.Fatalf("error while iterating %v", err)
}
// busy loop waiting for iter to be ready
for !iter.Ready() {
continue
Expand All @@ -115,7 +118,10 @@ func TestIteratorAscending(t *testing.T) {
t.Fatalf("Iter is not ready when it should be")
}

iter.Next()
_, err = iter.Next()
if err != nil {
t.Fatalf("error while iterating %v", err)
}
// busy loop waiting for iter to be ready
for !iter.Ready() {
continue
Expand All @@ -124,7 +130,10 @@ func TestIteratorAscending(t *testing.T) {
currentWindow = iter.windows[iter.index]
checkCurrentWindowIndex("02 Jan 06 15:07 +0000", currentWindow, t)

iter.Next()
_, err = iter.Next()
if err != nil {
t.Fatalf("error while iterating %v", err)
}
// busy loop waiting for iter to be ready
for !iter.Ready() {
continue
Expand All @@ -133,7 +142,10 @@ func TestIteratorAscending(t *testing.T) {
currentWindow = iter.windows[iter.index]
checkCurrentWindowIndex("02 Jan 06 15:09 +0000", currentWindow, t)

iter.Next()
_, err = iter.Next()
if err != nil {
t.Fatalf("error while iterating %v", err)
}
// busy loop waiting for iter to be ready
for !iter.Ready() {
continue
Expand All @@ -151,7 +163,10 @@ func TestIteratorDescending(t *testing.T) {
scenario := DefaultTestScenario()
iter := NewQueryIterator(scenario.StartTime(), scenario.EndTime(), false, scenario.QueryRunnerFunc(), scenario.HasDataFunc())

iter.Next()
_, err := iter.Next()
if err != nil {
t.Fatalf("error while iterating %v", err)
}
// busy loop waiting for iter to be ready
for !iter.Ready() {
continue
Expand All @@ -168,7 +183,10 @@ func TestIteratorDescending(t *testing.T) {
t.Fatalf("Iter is not ready when it should be")
}

iter.Next()
_, err = iter.Next()
if err != nil {
t.Fatalf("error while iterating %v", err)
}
// busy loop waiting for iter to be ready
for !iter.Ready() {
continue
Expand All @@ -177,7 +195,10 @@ func TestIteratorDescending(t *testing.T) {
currentWindow = iter.windows[iter.index]
checkCurrentWindowIndex("02 Jan 06 15:09 +0000", currentWindow, t)

iter.Next()
_, err = iter.Next()
if err != nil {
t.Fatalf("error while iterating %v", err)
}
// busy loop waiting for iter to be ready
for !iter.Ready() {
continue
Expand All @@ -186,7 +207,10 @@ func TestIteratorDescending(t *testing.T) {
currentWindow = iter.windows[iter.index]
checkCurrentWindowIndex("02 Jan 06 15:07 +0000", currentWindow, t)

iter.Next()
_, err = iter.Next()
if err != nil {
t.Fatalf("error while iterating %v", err)
}
// busy loop waiting for iter to be ready
for !iter.Ready() {
continue
Expand All @@ -202,7 +226,7 @@ func TestIteratorDescending(t *testing.T) {

func checkCurrentWindowIndex(expectedValue string, currentWindow MinuteCheckPoint, t *testing.T) {
expectedTime, _ := time.Parse(time.RFC822Z, expectedValue)
if !(currentWindow.time == expectedTime) {
if currentWindow.time != expectedTime {
t.Fatalf("window time does not match start, expected %s, actual %s", expectedTime.String(), currentWindow.time.String())
}
}
2 changes: 1 addition & 1 deletion pkg/model/defaultprofile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
render = focusedOuterStyle.Render(render)
}

fmt.Fprint(w, render)
_, _ = fmt.Fprint(w, render)
}

// Model for profile selection command
Expand Down
6 changes: 5 additions & 1 deletion pkg/model/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,11 @@ func fetchData(client *http.Client, profile *config.Profile, query string, start
}

err = json.NewDecoder(resp.Body).Decode(&data)
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
fmt.Printf("failed to close the response body %v\n", err)
}
}()
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/role/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (m *Model) Valid() bool {
case "admin", "editor", "none":
return true
case "writer", "reader", "ingestor":
return !(strings.Contains(m.Stream.Value(), " ") || m.Stream.Value() == "")
return !strings.Contains(m.Stream.Value(), " ") && m.Stream.Value() != ""
}
return true
}
Expand Down
Loading