-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (57 loc) · 1.44 KB
/
main.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
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
awsec2 "./awsec2"
parseconf "./parseconf"
)
func main() {
confs := parseconf.ParseConfigFile()
lis := parseconf.ListEnvFromConfig(confs)
_, envChosen := askFor("Please type %v and then press enter:\n", lis)
err, env := parseconf.GetVarsForThisEnv(envChosen, confs)
if nil != err {
log.Error("Unable to find vars for specified environment")
}
_, tagChosen := askFor("Microservice Searched\n", nil)
listPrivateIPs := awsec2.GetPrivateIpFromTag(tagChosen, env)
for _, elem := range listPrivateIPs {
fmt.Printf("IPs releaved %s\n", elem)
}
}
func askFor(question string, okayResponses []string) (bool, string) {
if okayResponses != nil {
fmt.Printf(question, okayResponses)
} else {
fmt.Printf(question)
}
var response string
_, err := fmt.Scanln(&response)
if err != nil {
log.Fatal(err)
}
if okayResponses != nil {
if containsString(okayResponses, response) {
return true, response
} else {
return askFor(question, okayResponses)
}
} else {
return true, response
}
}
func containsString(slice []string, element string) bool {
return !(posString(slice, element) == -1)
}
// posString returns the first index of element in slice.
// If slice does not contain element, returns -1.
func posString(slice []string, element string) int {
for index, elem := range slice {
if elem == element {
return index
}
}
return -1
}
func searchingForIPs(tag string) {
}