-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute.go
53 lines (46 loc) · 934 Bytes
/
execute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package sn
import (
"github.com/aws/aws-sdk-go-v2/service/ec2"
log "github.com/cantara/bragi/sbragi"
"github.com/cantara/nerthus2/cloud/aws/executor"
"github.com/cantara/nerthus2/cloud/aws/vpc"
)
type Requireing interface {
Subnets([]string) executor.Func
}
type data struct {
c *ec2.Client
v vpc.VPC
rs []Requireing
}
func Executor(rs []Requireing, c *ec2.Client) *data {
return &data{
c: c,
rs: rs,
}
}
func (d *data) Execute(c chan<- executor.Func) {
err := vpc.CreateSubnets(d.v, d.c)
if err != nil {
log.WithError(err).Error("while getting subnets")
c <- d.Execute
return
}
s, err := vpc.GetSubnets(d.v.Id, d.c)
if err != nil {
log.WithError(err).Error("while getting subnets")
c <- d.Execute
return
}
for _, r := range d.rs {
f := r.Subnets(vpc.SubnetsToIds(s))
if f == nil {
continue
}
c <- f
}
}
func (d *data) VPC(v vpc.VPC) executor.Func {
d.v = v
return d.Execute
}