Skip to content

Commit 288f12a

Browse files
committed
chore: add support for funcorder
1 parent 50eab58 commit 288f12a

File tree

6 files changed

+83
-82
lines changed

6 files changed

+83
-82
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ linters:
2929
- exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. [auto-fix]
3030
- fatcontext # Detects nested contexts in loops and function literals. [auto-fix]
3131
- forbidigo # Forbids identifiers [fast: true, auto-fix: false]
32+
- funcorder # Checks the order of functions, methods, and constructors. [fast]
3233
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false]
3334
- gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false]
3435
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]

internal/locality/regional/ids.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ type ID struct {
1414
Region scw.Region
1515
}
1616

17-
func (z ID) String() string {
18-
return fmt.Sprintf("%s/%s", z.Region, z.ID)
19-
}
20-
2117
func NewID(region scw.Region, id string) ID {
2218
return ID{
2319
ID: id,
2420
Region: region,
2521
}
2622
}
2723

24+
func (z ID) String() string {
25+
return fmt.Sprintf("%s/%s", z.Region, z.ID)
26+
}
27+
2828
func ExpandID(id interface{}) ID {
2929
regionalID := ID{}
3030
tab := strings.Split(id.(string), "/")

internal/locality/zonal/ids.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ type ID struct {
1414
Zone scw.Zone
1515
}
1616

17-
func (z ID) String() string {
18-
return fmt.Sprintf("%s/%s", z.Zone, z.ID)
19-
}
20-
2117
func NewID(zone scw.Zone, id string) ID {
2218
return ID{
2319
ID: id,
2420
Zone: zone,
2521
}
2622
}
2723

24+
func (z ID) String() string {
25+
return fmt.Sprintf("%s/%s", z.Zone, z.ID)
26+
}
27+
2828
func ExpandID(id interface{}) ID {
2929
zonedID := ID{}
3030
tab := strings.Split(id.(string), "/")

internal/meta/meta.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,45 +45,6 @@ type Meta struct {
4545
credentialsSource *CredentialsSource
4646
}
4747

48-
func (m Meta) ScwClient() *scw.Client {
49-
return m.scwClient
50-
}
51-
52-
func (m Meta) HTTPClient() *http.Client {
53-
return m.httpClient
54-
}
55-
56-
func (m Meta) AccessKeySource() string {
57-
return m.credentialsSource.AccessKey
58-
}
59-
60-
func (m Meta) SecretKeySource() string {
61-
return m.credentialsSource.SecretKey
62-
}
63-
64-
func (m Meta) ProjectIDSource() string {
65-
return m.credentialsSource.ProjectID
66-
}
67-
68-
func (m Meta) RegionSource() string {
69-
return m.credentialsSource.DefaultRegion
70-
}
71-
72-
func (m Meta) ZoneSource() string {
73-
return m.credentialsSource.DefaultZone
74-
}
75-
76-
type Config struct {
77-
ProviderSchema *schema.ResourceData
78-
HTTPClient *http.Client
79-
TerraformVersion string
80-
ForceZone scw.Zone
81-
ForceProjectID string
82-
ForceOrganizationID string
83-
ForceAccessKey string
84-
ForceSecretKey string
85-
}
86-
8748
// NewMeta creates the Meta object containing the SDK client.
8849
func NewMeta(ctx context.Context, config *Config) (*Meta, error) {
8950
////
@@ -149,6 +110,45 @@ func NewMeta(ctx context.Context, config *Config) (*Meta, error) {
149110
}, nil
150111
}
151112

113+
func (m Meta) ScwClient() *scw.Client {
114+
return m.scwClient
115+
}
116+
117+
func (m Meta) HTTPClient() *http.Client {
118+
return m.httpClient
119+
}
120+
121+
func (m Meta) AccessKeySource() string {
122+
return m.credentialsSource.AccessKey
123+
}
124+
125+
func (m Meta) SecretKeySource() string {
126+
return m.credentialsSource.SecretKey
127+
}
128+
129+
func (m Meta) ProjectIDSource() string {
130+
return m.credentialsSource.ProjectID
131+
}
132+
133+
func (m Meta) RegionSource() string {
134+
return m.credentialsSource.DefaultRegion
135+
}
136+
137+
func (m Meta) ZoneSource() string {
138+
return m.credentialsSource.DefaultZone
139+
}
140+
141+
type Config struct {
142+
ProviderSchema *schema.ResourceData
143+
HTTPClient *http.Client
144+
TerraformVersion string
145+
ForceZone scw.Zone
146+
ForceProjectID string
147+
ForceOrganizationID string
148+
ForceAccessKey string
149+
ForceSecretKey string
150+
}
151+
152152
func customizeUserAgent(providerVersion string, terraformVersion string) string {
153153
userAgent := fmt.Sprintf("terraform-provider/%s terraform/%s", providerVersion, terraformVersion)
154154

internal/services/instance/instancehelpers/block.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ import (
1111
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1212
)
1313

14-
func NewBlockAndInstanceAPI(client *scw.Client) *BlockAndInstanceAPI {
15-
instanceAPI := instance.NewAPI(client)
16-
blockAPI := block.NewAPI(client)
17-
18-
return &BlockAndInstanceAPI{
19-
API: instanceAPI,
20-
BlockAPI: blockAPI,
21-
}
22-
}
23-
2414
// InstanceAndBlockAPIWithZone returns a new instance API and the zone for a Create request
2515
func InstanceAndBlockAPIWithZone(d *schema.ResourceData, m interface{}) (*BlockAndInstanceAPI, scw.Zone, error) {
2616
zone, err := meta.ExtractZone(d, m)
@@ -46,6 +36,16 @@ type BlockAndInstanceAPI struct {
4636
BlockAPI *block.API
4737
}
4838

39+
func NewBlockAndInstanceAPI(client *scw.Client) *BlockAndInstanceAPI {
40+
instanceAPI := instance.NewAPI(client)
41+
blockAPI := block.NewAPI(client)
42+
43+
return &BlockAndInstanceAPI{
44+
API: instanceAPI,
45+
BlockAPI: blockAPI,
46+
}
47+
}
48+
4949
type GetUnknownVolumeRequest struct {
5050
VolumeID string
5151
Zone scw.Zone

internal/workerpool/workerpool.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@ func NewWorkerPool(size int) *WorkerPool {
2727
return p
2828
}
2929

30+
func (p *WorkerPool) AddTask(task Task) {
31+
p.tasksWaitingGroup.Add(1)
32+
p.tasksToDispatch <- task
33+
}
34+
35+
func (p *WorkerPool) CloseAndWait() []error {
36+
close(p.tasksToDispatch)
37+
p.tasksWaitingGroup.Wait()
38+
39+
return p.errors
40+
}
41+
42+
func (p *WorkerPool) worker() {
43+
for task := range p.tasksToRun {
44+
err := task()
45+
if err != nil {
46+
p.errorsMutex.Lock()
47+
p.errors = append(p.errors, err)
48+
p.errorsMutex.Unlock()
49+
}
50+
51+
p.tasksWaitingGroup.Done()
52+
}
53+
}
54+
3055
func (p *WorkerPool) dispatcher() {
3156
var pendingTasks []Task
3257

@@ -60,28 +85,3 @@ func (p *WorkerPool) dispatcher() {
6085
}
6186
}
6287
}
63-
64-
func (p *WorkerPool) worker() {
65-
for task := range p.tasksToRun {
66-
err := task()
67-
if err != nil {
68-
p.errorsMutex.Lock()
69-
p.errors = append(p.errors, err)
70-
p.errorsMutex.Unlock()
71-
}
72-
73-
p.tasksWaitingGroup.Done()
74-
}
75-
}
76-
77-
func (p *WorkerPool) AddTask(task Task) {
78-
p.tasksWaitingGroup.Add(1)
79-
p.tasksToDispatch <- task
80-
}
81-
82-
func (p *WorkerPool) CloseAndWait() []error {
83-
close(p.tasksToDispatch)
84-
p.tasksWaitingGroup.Wait()
85-
86-
return p.errors
87-
}

0 commit comments

Comments
 (0)