Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nanic committed Oct 23, 2023
1 parent 1efc5e5 commit 4ad9f41
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 40 deletions.
3 changes: 1 addition & 2 deletions cmd/alter/alter-partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}

Expand Down
48 changes: 24 additions & 24 deletions internal/broker/broker-operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions internal/common-operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/consume/AvroMessageDeserializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions internal/consume/PartitionConsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions internal/consumergroupoffsets/OffsetResettingConsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions internal/producer/AvroMessageSerializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions internal/producer/producer-operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4ad9f41

Please sign in to comment.