Skip to content

Commit 4bbae24

Browse files
committed
chore: add support for funcorder
1 parent e096766 commit 4bbae24

File tree

5 files changed

+44
-43
lines changed

5 files changed

+44
-43
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/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)