-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.go
73 lines (65 loc) · 1.42 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package tg
import (
"fmt"
elbv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
log "github.com/cantara/bragi/sbragi"
"github.com/cantara/nerthus2/cloud/aws/executor"
"github.com/cantara/nerthus2/cloud/aws/loadbalancer"
"github.com/cantara/nerthus2/cloud/aws/vpc"
)
type Requireing interface {
TG(loadbalancer.TargetGroup) executor.Func
}
type data struct {
c *elbv2.Client
env string
system string
cluster string
name string
path string
port int
v vpc.VPC
rs []Requireing
}
func Executor(env, system, cluster, path string, port int, rs []Requireing, c *elbv2.Client) *data {
return &data{
c: c,
env: env,
system: system,
cluster: cluster,
name: fmt.Sprintf("%s-%s-%s-tg", env, system, cluster), //This will be to long
path: path,
port: port,
rs: rs,
}
}
func (d *data) Execute(c chan<- executor.Func) {
tg, err := loadbalancer.GetTargetGroup(d.name, d.path, d.port, d.c)
if err == nil {
for _, r := range d.rs {
f := r.TG(tg)
if f == nil {
continue
}
c <- f
}
return
}
tg, err = loadbalancer.CreateTargetGroup(d.v.Id, d.name, d.path, d.port, d.c)
if err != nil {
log.WithError(err).Error("while creating new target group")
c <- d.Execute
return
}
for _, r := range d.rs {
f := r.TG(tg)
if f == nil {
continue
}
c <- f
}
}
func (d *data) VPC(v vpc.VPC) executor.Func {
d.v = v
return d.Execute
}