-
Notifications
You must be signed in to change notification settings - Fork 216
/
generate.go
66 lines (60 loc) · 1.81 KB
/
generate.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 remoteservices
import (
"strings"
"github.com/AlecAivazis/survey/v2"
"github.com/spaceuptech/space-cloud/space-cli/cmd/model"
"github.com/spaceuptech/space-cloud/space-cli/cmd/utils/input"
)
func generateService() (*model.SpecObject, error) {
project := ""
if err := input.Survey.AskOne(&survey.Input{Message: "Enter Project ID: "}, &project); err != nil {
return nil, err
}
service := ""
if err := input.Survey.AskOne(&survey.Input{Message: "Enter Service Name: "}, &service); err != nil {
return nil, err
}
url := ""
if err := input.Survey.AskOne(&survey.Input{Message: "Enter Service URL: ", Help: "e.g -> http://localhost:8090"}, &url); err != nil {
return nil, err
}
endpoints := make(map[string]interface{})
want := "y"
for {
endpointName := ""
if err := input.Survey.AskOne(&survey.Input{Message: "Enter Endpoint Name: "}, &endpointName); err != nil {
return nil, err
}
methods := ""
if err := input.Survey.AskOne(&survey.Select{Message: "Select Method: ", Options: []string{"POST", "PUT", "GET", "DELETE"}}, &methods); err != nil {
return nil, err
}
path := ""
if err := input.Survey.AskOne(&survey.Input{Message: "Enter URL Path:", Default: "/"}, &path); err != nil {
return nil, err
}
endpoints[endpointName] = map[string]interface{}{
"method": methods,
"path": path,
}
if err := input.Survey.AskOne(&survey.Input{Message: "Add another host?(Y/n)", Default: "n"}, &want); err != nil {
return nil, err
}
if strings.ToLower(want) == "n" {
break
}
}
v := &model.SpecObject{
API: "/v1/config/projects/{project}/remote-service/service/{id}",
Type: "remote-services",
Meta: map[string]string{
"id": service,
"project": project,
},
Spec: map[string]interface{}{
"url": url,
"endpoints": endpoints,
},
}
return v, nil
}