This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
/
base_controller.go
62 lines (53 loc) · 1.62 KB
/
base_controller.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
package main
import (
"fmt"
"os"
"regexp"
"strings"
)
type Controller struct {
Api *Api
}
func prompt(text string) string {
if replMode == true {
line, _ := term.Prompt(text)
return line
}
var response string
var err error
print(text + ": ")
_, err = fmt.Scanln(&response)
if err != nil {
fmt.Println("Error: ", err)
}
return response
}
func formatHostname(host string) string {
hostRegex := regexp.MustCompile(".(?:mongohq|mongolayer).com")
host = hostRegex.ReplaceAllLiteralString(host, "")
return host
}
func (c *Controller) pollNewDeployment(deployment Deployment) {
var err error
status := deployment.Status
for status == "new" {
fmt.Print(".")
deployment, err = c.Api.GetDeployment(deployment.Name)
if err != nil {
fmt.Println(err.Error())
fmt.Println("\nError pulling deployment information. For a manual update, please run:\n\n mongohq deployment:info --deployment " + deployment.Name)
os.Exit(1)
}
status = deployment.Status
}
fmt.Print("\n")
fmt.Println("Your database is ready. To add a user to your database, run:")
fmt.Println(" mongohq users:create --deployment " + deployment.Name + " --database " + deployment.Databases[0].Name + " -u <username>")
fmt.Println("")
fmt.Println("To connect to your database, run:")
fmt.Println(" mongo " + deployment.CurrentPrimary + "/" + deployment.Databases[0].Name + " -u <username>" + " -p")
fmt.Println("")
fmt.Println("Your applications should use the following URI to connect:")
fmt.Println(" mongodb://<username>:<password>@" + strings.Join(deployment.Members, ",") + "/" + deployment.Databases[0].Name)
fmt.Println("\nEnjoy!")
}