Skip to content

Commit 150d761

Browse files
committed
fix: lint fix
1 parent f5cdaac commit 150d761

File tree

2 files changed

+69
-62
lines changed

2 files changed

+69
-62
lines changed
Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,99 @@
11
package nautobot
22

33
import (
4-
"fmt"
5-
"io"
6-
"io/fs"
7-
"net/http"
8-
"os"
9-
"path/filepath"
10-
11-
nb "github.com/nautobot/go-nautobot/v2"
12-
"go.yaml.in/yaml/v3"
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"
1314
)
1415

1516
func ListYAMLFiles(dir string) ([]string, error) {
16-
var files []string
17+
var files []string
1718

18-
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
19-
if err != nil {
20-
return fmt.Errorf("error accessing %s: %w", path, err)
21-
}
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+
}
2223

23-
if d.IsDir() {
24-
return nil
25-
}
24+
if d.IsDir() {
25+
return nil
26+
}
2627

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

34-
if err != nil {
35-
return nil, err
36-
}
35+
if err != nil {
36+
return nil, err
37+
}
3738

38-
return files, nil
39+
return files, nil
3940
}
4041

4142
func ParseYAMLToStruct[T any](path string) (T, error) {
42-
var result T
43+
var result T
4344

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

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

53-
return result, nil
54+
return result, nil
5455
}
5556

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

6465
func buildNullableBulkWritableCircuitRequestTenant(uuid string) nb.NullableBulkWritableCircuitRequestTenant {
65-
return *nb.NewNullableBulkWritableCircuitRequestTenant(&nb.BulkWritableCircuitRequestTenant{
66-
Id: &nb.BulkWritableCableRequestStatusId{
67-
String: nb.PtrString(uuid),
68-
},
69-
})
66+
return *nb.NewNullableBulkWritableCircuitRequestTenant(&nb.BulkWritableCircuitRequestTenant{
67+
Id: &nb.BulkWritableCableRequestStatusId{
68+
String: nb.PtrString(uuid),
69+
},
70+
})
7071
}
7172

7273
func buildNullableBulkWritableRackRequestRackGroup(uuid string) *nb.NullableBulkWritableRackRequestRackGroup {
73-
return nb.NewNullableBulkWritableRackRequestRackGroup(&nb.BulkWritableRackRequestRackGroup{
74-
Id: &nb.BulkWritableCableRequestStatusId{
75-
String: nb.PtrString(uuid),
76-
},
77-
})
74+
return nb.NewNullableBulkWritableRackRequestRackGroup(&nb.BulkWritableRackRequestRackGroup{
75+
Id: &nb.BulkWritableCableRequestStatusId{
76+
String: nb.PtrString(uuid),
77+
},
78+
})
7879
}
7980

8081
// readResponseBody safely reads and closes the response body.
8182
// Returns the body content as a string. If resp is nil, returns empty string.
8283
func readResponseBody(resp *http.Response) string {
83-
if resp == nil || resp.Body == nil {
84-
return ""
85-
}
86-
defer resp.Body.Close()
87-
88-
bodyBytes, err := io.ReadAll(resp.Body)
89-
if err != nil {
90-
return fmt.Sprintf("failed to read response body: %v", err)
91-
}
92-
return string(bodyBytes)
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)
9399
}

go/rax/internal/nautobot/nautobot.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package nautobot
22

33
import (
4+
"strings"
5+
46
"github.com/charmbracelet/log"
57
nb "github.com/nautobot/go-nautobot/v2"
6-
"strings"
78
)
89

910
// NautobotClient holds the Nautobot API client and configuration.

0 commit comments

Comments
 (0)