From 4ad9f416d4279e440d1bd9e248d8ffb17cb55268 Mon Sep 17 00:00:00 2001 From: nanic Date: Mon, 23 Oct 2023 16:36:45 -0400 Subject: [PATCH] lint fixes --- cmd/alter/alter-partition.go | 3 +- internal/broker/broker-operation.go | 48 +++++++++---------- internal/common-operation.go | 3 +- internal/consume/AvroMessageDeserializer.go | 3 +- internal/consume/PartitionConsumer.go | 6 +-- .../OffsetResettingConsumer.go | 3 +- internal/producer/AvroMessageSerializer.go | 3 +- internal/producer/producer-operation.go | 3 +- 8 files changed, 32 insertions(+), 40 deletions(-) diff --git a/cmd/alter/alter-partition.go b/cmd/alter/alter-partition.go index 95a9f4c..9fe60fb 100644 --- a/cmd/alter/alter-partition.go +++ b/cmd/alter/alter-partition.go @@ -44,9 +44,8 @@ func newAlterPartitionCmd() *cobra.Command { return topic.CompleteTopicNames(cmd, args, toComplete) } else if len(args) == 1 { return partition.CompletePartitionIds(cmd, args, toComplete) - } else { - return nil, cobra.ShellCompDirectiveNoFileComp } + return nil, cobra.ShellCompDirectiveNoFileComp }, } diff --git a/internal/broker/broker-operation.go b/internal/broker/broker-operation.go index 2109f04..3444696 100644 --- a/internal/broker/broker-operation.go +++ b/internal/broker/broker-operation.go @@ -163,40 +163,40 @@ func (operation *Operation) DescribeBroker(id int32, flags DescribeBrokerFlags) return output.PrintObject(brokerInfo, flags.OutputFormat) } else if flags.OutputFormat != "" && flags.OutputFormat != "wide" { return errors.Errorf("unknown outputFormat: %s", flags.OutputFormat) - } else { - - tableWriter := output.CreateTableWriter() + } - // write broker info table - if err := tableWriter.WriteHeader("ID", "ADDRESS"); err != nil { - return err - } + tableWriter := output.CreateTableWriter() - if err := tableWriter.Write(fmt.Sprint(brokerInfo.ID), brokerInfo.Address); err != nil { - return err - } + // write broker info table + if err := tableWriter.WriteHeader("ID", "ADDRESS"); err != nil { + return err + } - if err := tableWriter.Flush(); err != nil { - return err - } + if err := tableWriter.Write(fmt.Sprint(brokerInfo.ID), brokerInfo.Address); err != nil { + return err + } - output.PrintStrings("") + if err := tableWriter.Flush(); err != nil { + return err + } - // first write config table - if err := tableWriter.WriteHeader("CONFIG", "VALUE"); err != nil { - return err - } + output.PrintStrings("") - for _, c := range brokerInfo.Configs { - if err := tableWriter.Write(c.Name, c.Value); err != nil { - return err - } - } + // first write config table + if err := tableWriter.WriteHeader("CONFIG", "VALUE"); err != nil { + return err + } - if err := tableWriter.Flush(); err != nil { + for _, c := range brokerInfo.Configs { + if err := tableWriter.Write(c.Name, c.Value); err != nil { return err } } + + if err := tableWriter.Flush(); err != nil { + return err + } + return nil } diff --git a/internal/common-operation.go b/internal/common-operation.go index 6531f09..53044ec 100644 --- a/internal/common-operation.go +++ b/internal/common-operation.go @@ -213,9 +213,8 @@ func GetClientID(context *ClientContext, defaultPrefix string) string { } else if usr, err = user.Current(); err != nil { output.Warnf("Failed to read current user: %v", err) return strings.TrimSuffix(defaultPrefix, "-") - } else { - return defaultPrefix + sanitizeUsername(usr.Username) } + return defaultPrefix + sanitizeUsername(usr.Username) } func sanitizeUsername(u string) string { diff --git a/internal/consume/AvroMessageDeserializer.go b/internal/consume/AvroMessageDeserializer.go index 079784d..33e6b27 100644 --- a/internal/consume/AvroMessageDeserializer.go +++ b/internal/consume/AvroMessageDeserializer.go @@ -171,9 +171,8 @@ func (deserializer AvroMessageDeserializer) CanDeserialize(topic string) (bool, return true, nil } else if util.ContainsString(subjects, topic+"-value") { return true, nil - } else { - return false, nil } + return false, nil } func (deserializer AvroMessageDeserializer) Deserialize(rawMsg *sarama.ConsumerMessage, flags Flags) error { diff --git a/internal/consume/PartitionConsumer.go b/internal/consume/PartitionConsumer.go index 3904168..ae17ae0 100644 --- a/internal/consume/PartitionConsumer.go +++ b/internal/consume/PartitionConsumer.go @@ -191,9 +191,8 @@ func getStartOffset(client *sarama.Client, topic string, flags Flags, currentPar return (*client).GetOffset(topic, currentPartition, sarama.OffsetOldest) } else if len(flags.Offsets) > 0 { return extractOffsetForPartition(flags, currentPartition) - } else { - return sarama.OffsetNewest, nil } + return sarama.OffsetNewest, nil } func getEndOffset(client *sarama.Client, topic string, flags Flags, currentPartition int32) (int64, error) { @@ -210,9 +209,8 @@ func getEndOffset(client *sarama.Client, topic string, flags Flags, currentParti return ErrOffset, err } return newestOffset, nil - } else { - return sarama.OffsetNewest, nil } + return sarama.OffsetNewest, nil } func extractOffsetForPartition(flags Flags, currentPartition int32) (int64, error) { diff --git a/internal/consumergroupoffsets/OffsetResettingConsumer.go b/internal/consumergroupoffsets/OffsetResettingConsumer.go index 472d874..325428b 100644 --- a/internal/consumergroupoffsets/OffsetResettingConsumer.go +++ b/internal/consumergroupoffsets/OffsetResettingConsumer.go @@ -150,9 +150,8 @@ func getPartitionOffsets(client *sarama.Client, topic string, partition int32, f return offsets, errors.Errorf("cannot set offset for Partition %d: offset (%d) < oldest offset (%d)", partition, flags.Offset, offsets.OldestOffset) } else if flags.Offset > offsets.NewestOffset { return offsets, errors.Errorf("cannot set offset for Partition %d: offset (%d) > newest offset (%d)", partition, flags.Offset, offsets.NewestOffset) - } else { - offsets.TargetOffset = flags.Offset } + offsets.TargetOffset = flags.Offset } else { if flags.OldestOffset { offsets.TargetOffset = offsets.OldestOffset diff --git a/internal/producer/AvroMessageSerializer.go b/internal/producer/AvroMessageSerializer.go index 4abda6a..d2af98f 100644 --- a/internal/producer/AvroMessageSerializer.go +++ b/internal/producer/AvroMessageSerializer.go @@ -106,9 +106,8 @@ func (serializer AvroMessageSerializer) CanSerialize(topic string) (bool, error) return true, nil } else if util.ContainsString(subjects, topic+"-value") { return true, nil - } else { - return false, nil } + return false, nil } func (serializer AvroMessageSerializer) Serialize(key, value []byte, flags Flags) (*sarama.ProducerMessage, error) { diff --git a/internal/producer/producer-operation.go b/internal/producer/producer-operation.go index c2a57a7..350ac21 100644 --- a/internal/producer/producer-operation.go +++ b/internal/producer/producer-operation.go @@ -339,9 +339,8 @@ func resolveColumns(line []string) (keyColumnIdx, valueColumnIdx, columnCount in } else if isTimestamp(line[1]) { output.Warnf("assuming column 1 to be message timestamp. Column will be ignored") return 0, 2, 3, nil - } else { - return -1, -1, -1, errors.Errorf("line contains unexpected amount of separators:\n%s", line) } + return -1, -1, -1, errors.Errorf("line contains unexpected amount of separators:\n%s", line) } func isTimestamp(value string) bool {