add Go lint

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2022-07-16 20:21:11 +08:00
parent cc13492623
commit ac23def893
60 changed files with 576 additions and 194 deletions
+7 -7
View File
@@ -93,15 +93,15 @@ func run(cmd *cobra.Command, args []string) {
for _, p := range ps.list {
switch {
case p.left != nil && p.right == nil:
fmt.Fprintf(os.Stderr, "Only in %s: %s\n", leftPath, p.left.getId())
fmt.Fprintf(os.Stderr, "Only in %s: %s\n", leftPath, p.left.getID())
exitCode = 1
case p.left == nil && p.right != nil:
fmt.Fprintf(os.Stderr, "Only in %s: %s\n", rightPath, p.right.getId())
fmt.Fprintf(os.Stderr, "Only in %s: %s\n", rightPath, p.right.getID())
exitCode = 1
default:
diff := deep.Equal(p.left, p.right)
if diff != nil {
id := p.left.getId()
id := p.left.getID()
fmt.Fprintf(os.Stderr, "< %s %s\n", id, leftPath)
fmt.Fprintf(os.Stderr, "> %s %s\n", id, rightPath)
for _, d := range diff {
@@ -160,7 +160,9 @@ func readManifest(path string) ([]resource, error) {
if err != nil {
return nil, err
}
defer f.Close()
defer func() {
_ = f.Close()
}()
decoder := yaml.NewYAMLToJSONDecoder(f)
resources := []resource{}
for {
@@ -179,7 +181,7 @@ func readManifest(path string) ([]resource, error) {
return resources, nil
}
func (res resource) getId() string {
func (res resource) getID() string {
meta, err := res.getMeta()
if err != nil {
return fmt.Sprintf("%v", res)
@@ -202,7 +204,6 @@ func (res resource) getId() string {
}
gvk := strings.Join([]string{gv, k}, "_")
return strings.Join([]string{gvk, ns, nm}, "|")
}
// lifted from kustomize/kyaml/kio/filters/merge3.go
@@ -267,7 +268,6 @@ func (p *pair) add(node resource, source diffSource) error {
return fmt.Errorf("unknown diff source value: %s", source)
}
return nil
}
func main() {
-1
View File
@@ -242,5 +242,4 @@ func TestTmplStrings(t *testing.T) {
require.Equal(t, tc.output, tplResult.String())
})
}
}
+2 -2
View File
@@ -113,10 +113,10 @@ func computeDiff(formatter aurora.Aurora, a interface{}, b interface{}) (string,
switch {
case strings.HasPrefix(s, "+"):
diffs = append(diffs, formatter.Bold(formatter.Green(s)).String())
ndiffs += 1
ndiffs++
case strings.HasPrefix(s, "-"):
diffs = append(diffs, formatter.Bold(formatter.Red(s)).String())
ndiffs += 1
ndiffs++
default:
diffs = append(diffs, s)
}