Skip to content

Commit daf1b71

Browse files
committed
fix lint:
1 parent 4fd6475 commit daf1b71

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

internal/services/domain/helpers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ func getRecordFromTypeAndData(dnsType domain.RecordType, data string, records []
4040
if currentRecord != nil {
4141
return nil, errors.New("multiple records found with same type and data")
4242
}
43+
4344
currentRecord = r
45+
4446
break
4547
}
4648
} else {
4749
if strings.HasPrefix(flattedData, flattenCurrentData) && r.Type == dnsType {
4850
if currentRecord != nil {
4951
return nil, errors.New("multiple records found with same type and data")
5052
}
53+
5154
currentRecord = r
55+
5256
break
5357
}
5458
}

internal/services/domain/types.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ import (
88
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
99
)
1010

11-
// getStringSafely safely extracts a string value from an interface
12-
func getStringSafely(v any) string {
13-
if s, ok := v.(string); ok {
14-
return s
15-
}
16-
return ""
17-
}
18-
1911
func flattenDomainData(data string, recordType domain.RecordType) any {
2012
switch recordType {
2113
case domain.RecordTypeMX: // API return this format: "{priority} {data}"
@@ -39,11 +31,13 @@ func normalizeSRVData(data string) string {
3931
if len(parts) >= 4 {
4032
priority, weight, port, target := parts[0], parts[1], parts[2], parts[3]
4133
target = removeZoneDomainSuffix(target)
34+
4235
return strings.Join([]string{priority, weight, port, target}, " ")
4336
}
4437

4538
if len(parts) == 3 {
4639
priority, port, target := parts[0], parts[1], parts[2]
40+
4741
return strings.Join([]string{priority, "0", port, target}, " ")
4842
}
4943

@@ -181,34 +175,22 @@ func expandDomainHTTPService(i any, ok bool) *domain.RecordHTTPServiceConfig {
181175
return nil
182176
}
183177

184-
lst, ok := i.([]any)
185-
if !ok || len(lst) == 0 {
186-
return nil
187-
}
188-
189-
rawMap, ok := lst[0].(map[string]any)
190-
if !ok {
191-
return nil
192-
}
178+
rawMap := i.([]any)[0].(map[string]any)
193179

194180
ips := []net.IP{}
195181

196182
rawIPs, ok := rawMap["ips"].([]any)
197183
if ok {
198184
for _, rawIP := range rawIPs {
199-
if s, ok := rawIP.(string); ok {
200-
if ip := net.ParseIP(s); ip != nil {
201-
ips = append(ips, ip)
202-
}
203-
}
185+
ips = append(ips, net.ParseIP(rawIP.(string)))
204186
}
205187
}
206188

207189
return &domain.RecordHTTPServiceConfig{
208190
MustContain: types.ExpandStringPtr(rawMap["must_contain"]),
209-
URL: getStringSafely(rawMap["url"]),
191+
URL: rawMap["url"].(string),
210192
UserAgent: types.ExpandStringPtr(rawMap["user_agent"]),
211-
Strategy: domain.RecordHTTPServiceConfigStrategy(getStringSafely(rawMap["strategy"])),
193+
Strategy: domain.RecordHTTPServiceConfigStrategy(rawMap["strategy"].(string)),
212194
IPs: ips,
213195
}
214196
}

0 commit comments

Comments
 (0)