Skip to content

Commit 140ba63

Browse files
committed
fix: lint fix
1 parent 150d761 commit 140ba63

File tree

2 files changed

+64
-71
lines changed

2 files changed

+64
-71
lines changed

go/rax/internal/controller/nautobot_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (r *NautobotReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
9292
}
9393

9494
n := nautobot.NewNautobotClient(fmt.Sprintf("http://%s/api", nautobotService.Spec.ClusterIP), nautobotAuthToken)
95-
n.SyncAllDeviceTypes(ctx, deviceTypeMap)
95+
_ = n.SyncAllDeviceTypes(ctx, deviceTypeMap)
9696
// Update status
9797
nautobotCR.Status.LastSyncedAt = metav1.Now()
9898
nautobotCR.Status.Ready = true
Lines changed: 63 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,92 @@
11
package nautobot
22

33
import (
4-
"fmt"
5-
"github.com/charmbracelet/log"
6-
"io"
7-
"io/fs"
8-
"net/http"
9-
"os"
10-
"path/filepath"
11-
12-
nb "github.com/nautobot/go-nautobot/v2"
13-
"go.yaml.in/yaml/v3"
4+
"fmt"
5+
"io"
6+
"io/fs"
7+
"net/http"
8+
"os"
9+
"path/filepath"
10+
11+
"github.com/charmbracelet/log"
12+
13+
nb "github.com/nautobot/go-nautobot/v2"
14+
"go.yaml.in/yaml/v3"
1415
)
1516

1617
func ListYAMLFiles(dir string) ([]string, error) {
17-
var files []string
18+
var files []string
1819

19-
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
20-
if err != nil {
21-
return fmt.Errorf("error accessing %s: %w", path, err)
22-
}
20+
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
21+
if err != nil {
22+
return fmt.Errorf("error accessing %s: %w", path, err)
23+
}
2324

24-
if d.IsDir() {
25-
return nil
26-
}
25+
if d.IsDir() {
26+
return nil
27+
}
2728

28-
ext := filepath.Ext(path)
29-
if ext == ".yaml" || ext == ".yml" {
30-
files = append(files, path)
31-
}
32-
return nil
33-
})
29+
ext := filepath.Ext(path)
30+
if ext == ".yaml" || ext == ".yml" {
31+
files = append(files, path)
32+
}
33+
return nil
34+
})
3435

35-
if err != nil {
36-
return nil, err
37-
}
36+
if err != nil {
37+
return nil, err
38+
}
3839

39-
return files, nil
40+
return files, nil
4041
}
4142

4243
func ParseYAMLToStruct[T any](path string) (T, error) {
43-
var result T
44+
var result T
4445

45-
data, err := os.ReadFile(path)
46-
if err != nil {
47-
return result, fmt.Errorf("failed to read file %s: %w", path, err)
48-
}
46+
data, err := os.ReadFile(path)
47+
if err != nil {
48+
return result, fmt.Errorf("failed to read file %s: %w", path, err)
49+
}
4950

50-
if err := yaml.Unmarshal(data, &result); err != nil {
51-
return result, fmt.Errorf("failed to parse YAML %s: %w", path, err)
52-
}
51+
if err := yaml.Unmarshal(data, &result); err != nil {
52+
return result, fmt.Errorf("failed to parse YAML %s: %w", path, err)
53+
}
5354

54-
return result, nil
55+
return result, nil
5556
}
5657

5758
func buildBulkWritableCableRequestStatus(uuid string) *nb.BulkWritableCableRequestStatus {
58-
return &nb.BulkWritableCableRequestStatus{
59-
Id: &nb.BulkWritableCableRequestStatusId{
60-
String: nb.PtrString(uuid),
61-
},
62-
}
59+
return &nb.BulkWritableCableRequestStatus{
60+
Id: &nb.BulkWritableCableRequestStatusId{
61+
String: nb.PtrString(uuid),
62+
},
63+
}
6364
}
6465

6566
func buildNullableBulkWritableCircuitRequestTenant(uuid string) nb.NullableBulkWritableCircuitRequestTenant {
66-
return *nb.NewNullableBulkWritableCircuitRequestTenant(&nb.BulkWritableCircuitRequestTenant{
67-
Id: &nb.BulkWritableCableRequestStatusId{
68-
String: nb.PtrString(uuid),
69-
},
70-
})
71-
}
72-
73-
func buildNullableBulkWritableRackRequestRackGroup(uuid string) *nb.NullableBulkWritableRackRequestRackGroup {
74-
return nb.NewNullableBulkWritableRackRequestRackGroup(&nb.BulkWritableRackRequestRackGroup{
75-
Id: &nb.BulkWritableCableRequestStatusId{
76-
String: nb.PtrString(uuid),
77-
},
78-
})
67+
return *nb.NewNullableBulkWritableCircuitRequestTenant(&nb.BulkWritableCircuitRequestTenant{
68+
Id: &nb.BulkWritableCableRequestStatusId{
69+
String: nb.PtrString(uuid),
70+
},
71+
})
7972
}
8073

8174
// readResponseBody safely reads and closes the response body.
8275
// Returns the body content as a string. If resp is nil, returns empty string.
8376
func readResponseBody(resp *http.Response) string {
84-
if resp == nil || resp.Body == nil {
85-
return ""
86-
}
87-
defer func(Body io.ReadCloser) {
88-
err := Body.Close()
89-
if err != nil {
90-
log.Info("failed to close response body", "error", err)
91-
}
92-
}(resp.Body)
93-
94-
bodyBytes, err := io.ReadAll(resp.Body)
95-
if err != nil {
96-
return fmt.Sprintf("failed to read response body: %v", err)
97-
}
98-
return string(bodyBytes)
77+
if resp == nil || resp.Body == nil {
78+
return ""
79+
}
80+
defer func(Body io.ReadCloser) {
81+
err := Body.Close()
82+
if err != nil {
83+
log.Info("failed to close response body", "error", err)
84+
}
85+
}(resp.Body)
86+
87+
bodyBytes, err := io.ReadAll(resp.Body)
88+
if err != nil {
89+
return fmt.Sprintf("failed to read response body: %v", err)
90+
}
91+
return string(bodyBytes)
9992
}

0 commit comments

Comments
 (0)