本文整理汇总了Golang中github.com/runabove/sail/internal.Check函数的典型用法代码示例。如果您正苦于以下问题:Golang Check函数的具体用法?Golang Check怎么用?Golang Check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: repositoryList
func repositoryList(apps []string) {
w := tabwriter.NewWriter(os.Stdout, 30, 1, 3, ' ', 0)
titles := []string{"NAME", "TAG", "TYPE", "PRIVACY", "SOURCE"}
fmt.Fprintln(w, strings.Join(titles, "\t"))
repositories := []string{}
var repository map[string]interface{}
for _, app := range apps {
b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/repositories/%s", app), nil)
internal.Check(json.Unmarshal(b, &repositories))
for _, repositoryID := range repositories {
b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/repositories/%s/%s", app, repositoryID), nil)
internal.Check(json.Unmarshal(b, &repository))
tags := repository["tags"]
if tags == "" {
tags = "-"
}
source := repository["source"]
if source == nil || source == "" {
source = "-"
}
fmt.Fprintf(w, "%s/%s\t%s\t%s\t%s\t%s\n", app, repository["name"], tags, repository["type"], repository["privacy"], source)
w.Flush()
}
}
}
示例2: serviceDomainDetach
func serviceDomainDetach(serviceID, domain string, args domainStruct) {
// Split namespace and service
host, app, service, tag, err := internal.ParseResourceName(serviceID)
internal.Check(err)
if !internal.CheckHostConsistent(host) {
fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
os.Exit(1)
} else if len(tag) > 0 {
fmt.Fprintf(os.Stderr, "Error: Invalid service name. Please see sail service domain detach --help\n")
os.Exit(1)
}
body, err := json.Marshal(args)
internal.Check(err)
// Sanity checks
err = internal.CheckName(domain)
internal.Check(err)
path := fmt.Sprintf("/applications/%s/services/%s/attached-routes/%s", app, service, domain)
data := internal.DeleteBodyWantJSON(path, body)
internal.FormatOutput(data, func(data []byte) {
fmt.Fprintf(os.Stderr, "Detached route %s %s%s from service %s/%s\n", args.Method, domain, args.Pattern, app, service)
})
}
示例3: serviceScale
// serviceScale start service (without attach)
func serviceScale(app string, service string, number int, destroy bool, batch bool) {
if !batch {
internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
}
path := fmt.Sprintf("/applications/%s/services/%s/scale?stream", app, service)
args := Scale{
Number: number,
Destroy: destroy,
}
data, err := json.Marshal(&args)
internal.Check(err)
buffer, _, err := internal.Stream("POST", path, data)
internal.Check(err)
line, err := internal.DisplayStream(buffer)
internal.Check(err)
if line != nil {
var data map[string]interface{}
err = json.Unmarshal(line, &data)
internal.Check(err)
fmt.Printf("Hostname: %v\n", data["hostname"])
fmt.Printf("Running containers: %v/%v\n", data["container_number"], data["container_target"])
}
if !batch {
internal.ExitAfterCtrlC()
}
}
示例4: doServiceRedeploy
func doServiceRedeploy(args Redeploy, app, service string) {
path := fmt.Sprintf("/applications/%s/services/%s/redeploy", app, service)
body, err := json.MarshalIndent(args, " ", " ")
if err != nil {
fmt.Fprintf(os.Stderr, "Fatal: %s\n", err)
return
}
// Attach console
if !redeployBatch {
internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
}
// Redeploy
buffer, _, err := internal.Stream("POST", path, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
line, err := internal.DisplayStream(buffer)
internal.Check(err)
if len(line) > 0 {
var data map[string]interface{}
err = json.Unmarshal(line, &data)
internal.Check(err)
fmt.Printf("Hostname: %v\n", data["hostname"])
}
if !redeployBatch {
internal.ExitAfterCtrlC()
}
}
示例5: networkShow
func networkShow(networkID string) {
// Split namespace and repository
host, app, net, tag, err := internal.ParseResourceName(networkID)
internal.Check(err)
if !internal.CheckHostConsistent(host) {
fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
os.Exit(1)
} else if len(tag) > 0 {
fmt.Fprintf(os.Stderr, "Error: Invalid network name. Please see sail network show --help\n")
os.Exit(1)
}
var network map[string]interface{}
var ranges []string
b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/networks/%s", app, net), nil)
internal.Check(json.Unmarshal(b, &network))
brange := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/networks/%s/ranges", app, net), nil)
internal.Check(json.Unmarshal(brange, &ranges))
network["range"] = ranges
n, err := json.Marshal(network)
internal.Check(err)
internal.FormatOutputDef(n)
}
示例6: cmdUp
func cmdUp(cmd *cobra.Command, args []string) {
// Check args
if len(args) != 1 {
internal.Exit("Invalid usage. sail compose up <namespace>. Please see sail compose up -h\n")
}
ns := args[0]
// Try to read file
payload, err := ioutil.ReadFile(upFile)
if err != nil {
internal.Exit("Error reading compose file: %s\n", err)
}
// Execute request
path := fmt.Sprintf("/applications/%s/fig/up?stream", ns)
buffer, _, err := internal.Stream("POST", path, payload, internal.SetHeader("Content-Type", "application/x-yaml"))
internal.Check(err)
// Display api stream
line, err := internal.DisplayStream(buffer)
internal.Check(err)
if line != nil {
var data map[string]interface{}
err = json.Unmarshal(line, &data)
internal.Check(err)
fmt.Printf("Hostname: %v\n", data["hostname"])
fmt.Printf("Running containers: %v/%v\n", data["container_number"], data["container_target"])
}
}
示例7: serviceStart
// serviceStart start service (without attach)
func serviceStart(app string, service string, batch bool) {
if !batch {
internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
}
// stream service events in a goroutine
internal.EventStreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/events", app, service), nil, true)
path := fmt.Sprintf("/applications/%s/services/%s/start", app, service)
buffer, _, err := internal.Stream("POST", path, []byte("{}"))
internal.Check(err)
line, err := internal.DisplayStream(buffer)
internal.Check(err)
if len(line) > 0 {
var data map[string]interface{}
err = json.Unmarshal(line, &data)
internal.Check(err)
fmt.Printf("Hostname: %v\n", data["hostname"])
}
if !batch {
internal.ExitAfterCtrlC()
}
}
示例8: serviceScale
// serviceScale start service (without attach)
func serviceScale(app string, service string, number int, destroy bool, batch bool) {
if !batch {
internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
}
// stream service events in a goroutine
internal.EventStreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/events", app, service), nil, true)
path := fmt.Sprintf("/applications/%s/services/%s/scale", app, service)
args := Scale{
Number: number,
Destroy: destroy,
}
data, err := json.Marshal(&args)
internal.Check(err)
buffer, _, err := internal.Stream("POST", path, data)
internal.Check(err)
line, err := internal.DisplayStream(buffer)
internal.Check(err)
if len(line) > 0 {
var data map[string]interface{}
err = json.Unmarshal(line, &data)
internal.Check(err)
fmt.Printf("Hostname: %v\n", data["hostname"])
}
if !batch {
internal.ExitAfterCtrlC()
}
}
示例9: serviceList
func serviceList(apps []string) {
w := tabwriter.NewWriter(os.Stdout, 27, 1, 2, ' ', 0)
titles := []string{"NAME", "REPOSITORY", "IMAGE ID", "STATE", "CONTAINERS", "CREATED", "NETWORK"}
fmt.Fprintln(w, strings.Join(titles, "\t"))
services := []string{}
var service map[string]interface{}
for _, app := range apps {
b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/services", app), nil)
internal.Check(json.Unmarshal(b, &services))
for _, serviceID := range services {
b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/services/%s", app, serviceID), nil)
internal.Check(json.Unmarshal(b, &service))
ips := []string{}
for _, container := range service["containers"].(map[string]interface{}) {
for name, network := range container.(map[string]interface{})["network"].(map[string]interface{}) {
ips = append(ips, fmt.Sprintf("%s:%s", name, network.(map[string]interface{})["ip"]))
}
}
fmt.Fprintf(w, "%s/%s\t%[email protected]%s\t%s\t%s\t%d\t%s\t%s\n",
app, service["name"],
service["repository"],
service["repository_tag"],
service["image"].(string)[:12],
strings.ToUpper(service["state"].(string)),
int(service["container_number"].(float64)),
service["creation_date"].(string)[:19],
strings.Join(ips, ","))
w.Flush()
}
}
}
示例10: domainListFormatter
func domainListFormatter(data []byte) {
var routes []map[string]interface{}
internal.Check(json.Unmarshal(data, &routes))
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
// below this: horrible hack. Do I feel ashamed: Yes.
if !domainHeadersDone {
titles := []string{"APP", "SERVICE", "DOMAIN", "METHOD", "PATTERN"}
fmt.Fprintln(w, strings.Join(titles, "\t"))
domainHeadersDone = true
}
for _, route := range routes {
app := route["namespace"]
service := route["service"]
if app == nil {
app = "-"
}
if service == nil {
service = "-"
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", app, service, route["domain"], route["method"], route["pattern"])
w.Flush()
}
}
示例11: sshKeyList
func sshKeyList() {
type keyStruct struct {
Name string `json:"name"`
Fingerprint string `json:"fingerprint"`
PublicKey string `json:"public_key"`
}
b := internal.ReqWant("GET", http.StatusOK, "/user/keys", nil)
var keys []keyStruct
err := json.Unmarshal(b, &keys)
internal.Check(err)
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
titles := []string{"NAME", "FINGERPRINT"}
fmt.Fprintln(w, strings.Join(titles, "\t"))
for _, key := range keys {
fmt.Fprintf(w, "%s\t%s\n",
key.Name,
key.Fingerprint,
)
}
w.Flush()
}
示例12: cmdLogs
func cmdLogs(cmd *cobra.Command, args []string) {
usage := "usage: sail containers logs [<applicationName>/]<containerId>"
if len(args) != 1 {
fmt.Fprintln(os.Stderr, usage)
os.Exit(1)
}
// Split namespace and container
host, app, container, tag, err := internal.ParseResourceName(args[0])
internal.Check(err)
if !internal.CheckHostConsistent(host) {
fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
os.Exit(1)
} else if len(tag) > 0 {
fmt.Fprintf(os.Stderr, "Error: Invalid container name. Please see sail container logs --help\n")
os.Exit(1)
}
// Get args
logsBody.Application = app
logsBody.Container = container
containerLogs(logsBody)
}
示例13: cmdAdd
func cmdAdd(cmd *cobra.Command, args []string) {
cmdAddBody.ContainerNetwork = make(map[string]map[string][]string)
cmdAddBody.Links = make(map[string]string)
cmdAddBody.ContainerPorts = make(map[string][]PortConfig)
cmdAddBody.ContainerCommand = make([]string, 0)
if len(args) < 2 {
fmt.Fprintln(os.Stderr, cmdAddUsage)
os.Exit(1)
}
// Split namespace and repository
host, app, repo, tag, err := internal.ParseResourceName(args[0])
internal.Check(err)
cmdAddBody.Application = app
cmdAddBody.Repository = repo
cmdAddBody.RepositoryTag = tag
if !internal.CheckHostConsistent(host) {
fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
os.Exit(1)
}
// Service name
if len(args) >= 2 {
cmdAddBody.Service = args[1]
} else {
cmdAddBody.Service = cmdAddBody.Repository
}
serviceAdd(cmdAddBody)
}
示例14: containerList
func containerList(apps []string) {
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
titles := []string{"APPLICATION", "SERVICE", "CONTAINER", "STATE", "DEPLOYED"}
fmt.Fprintln(w, strings.Join(titles, "\t"))
containers := []string{}
var container map[string]interface{}
for _, app := range apps {
b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/containers", app), nil)
internal.Check(json.Unmarshal(b, &containers))
for _, containerID := range containers {
b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/containers/%s", app, containerID), nil)
internal.Check(json.Unmarshal(b, &container))
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t\n", app, container["service"], container["name"], strings.ToUpper(container["state"].(string)), container["deployment_date"])
w.Flush()
}
}
}
示例15: repositoryAdd
func repositoryAdd(repositoryName string, args repositoryAddStruct) {
// Split namespace and repository
host, app, repo, tag, err := internal.ParseResourceName(repositoryName)
internal.Check(err)
if !internal.CheckHostConsistent(host) {
fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
os.Exit(1)
} else if len(tag) > 0 {
fmt.Fprintf(os.Stderr, "Error: Invalid repository name. Please see sail repository add --help\n")
os.Exit(1)
}
body, err := json.Marshal(args)
internal.Check(err)
path := fmt.Sprintf("/repositories/%s/%s", app, repo)
internal.FormatOutputDef(internal.PostBodyWantJSON(path, body))
}