本文整理匯總了Golang中github.com/flexiant/concerto/webservice.NewWebService函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewWebService函數的具體用法?Golang NewWebService怎麽用?Golang NewWebService使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewWebService函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: cmdAdd
func cmdAdd(c *cli.Context) {
utils.FlagsRequired(c, []string{"cidr", "minPort", "maxPort", "ipProtocol"})
// API accepts only 1 rule
newRule := &Rule{
c.String("ipProtocol"),
c.String("cidr"),
c.Int("minPort"),
c.Int("maxPort"),
}
policy := get()
exists := check(policy, *newRule)
if exists == false {
policy.Rules = append(policy.Rules, *newRule)
webservice, err := webservice.NewWebService()
utils.CheckError(err)
nRule := make(map[string]Rule)
nRule["rule"] = *newRule
json, err := json.Marshal(nRule)
utils.CheckError(err)
err, res, code := webservice.Post(fmt.Sprintf("%s/rules", endpoint), json)
if res == nil {
log.Fatal(err)
}
utils.CheckError(err)
utils.CheckReturnCode(code, res)
}
}
示例2: cmdReorderTemplateScripts
func cmdReorderTemplateScripts(c *cli.Context) {
utils.FlagsRequired(c, []string{"template_id", "type", "script_ids"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
v := make(map[string]interface{})
v["type"] = c.String("type")
v["script_ids"] = c.GlobalStringSlice("script_ids")
jsonBytes, err := json.Marshal(v)
utils.CheckError(err)
err, res, code := webservice.Put(fmt.Sprintf("/v1/blueprint/templates/%s/scripts/reorder", c.String("template_id")), jsonBytes)
utils.CheckError(err)
utils.CheckReturnCode(code, res)
var templateScripts []TemplateScript
err = json.Unmarshal(res, &templateScripts)
utils.CheckError(err)
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tTYPE\tEXECUTION ORDER\tTEMPLATE ID\tSCRIPT ID\tPARAMETER VALUES\r")
for _, templateScript := range templateScripts {
fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\n", templateScript.Id, templateScript.Type, templateScript.Execution_Order, templateScript.Template_Id, templateScript.Script_Id, templateScript.Parameter_Values)
}
w.Flush()
}
示例3: cmdUpdateTemplateScript
func cmdUpdateTemplateScript(c *cli.Context) {
utils.FlagsRequired(c, []string{"id", "template_id"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
v := make(map[string]interface{})
if c.IsSet("parameter_values") {
var params TemplateScriptCredentials
err = json.Unmarshal([]byte(c.String("credentials")), ¶ms)
v["parameter_values"] = params
}
jsonBytes, err := json.Marshal(v)
utils.CheckError(err)
err, res, code := webservice.Put(fmt.Sprintf("/v1/blueprint/templates/%s/scripts/%s", c.String("template_id"), c.String("id")), jsonBytes)
utils.CheckError(err)
utils.CheckReturnCode(code, res)
var templateScript TemplateScript
err = json.Unmarshal(res, &templateScript)
utils.CheckError(err)
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tTYPE\tEXECUTION ORDER\tTEMPLATE ID\tSCRIPT ID\tPARAMETER VALUES\r")
fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\n", templateScript.Id, templateScript.Type, templateScript.Execution_Order, templateScript.Template_Id, templateScript.Script_Id, templateScript.Parameter_Values)
w.Flush()
}
示例4: cmdUpdate
func cmdUpdate(c *cli.Context) {
utils.FlagsRequired(c, []string{"id"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
v := make(map[string]string)
if c.IsSet("name") {
v["name"] = c.String("name")
}
if c.IsSet("public_key") {
v["public_key"] = c.String("public_key")
}
if c.IsSet("private_key") {
v["private_key"] = c.String("private_key")
}
jsonBytes, err := json.Marshal(v)
utils.CheckError(err)
err, res, code := webservice.Put(fmt.Sprintf("/v1/cloud/ssh_profiles/%s", c.String("id")), jsonBytes)
utils.CheckError(err)
utils.CheckReturnCode(code, res)
var sshProfile SSHProfile
err = json.Unmarshal(res, &sshProfile)
utils.CheckError(err)
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tNAME\rPUBLIC KEY\tPRIVATE KEY\r")
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", sshProfile.Id, sshProfile.Name, sshProfile.Public_key, sshProfile.Private_key)
w.Flush()
}
示例5: cmdCreate
func cmdCreate(c *cli.Context) {
utils.FlagsRequired(c, []string{"saas_provider_id", "account_data"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
credentialsString := []byte(c.String("account_data"))
var jsonCredentials SaasRequiredCredentials
err = json.Unmarshal(credentialsString, &jsonCredentials)
v := make(map[string]interface{})
v["saas_provider_id"] = c.String("saas_provider_id")
v["account_data"] = jsonCredentials
jsonBytes, err := json.Marshal(v)
utils.CheckError(err)
err, res, code := webservice.Post("/v1/settings/saas_accounts", jsonBytes)
if res == nil {
log.Fatal(err)
}
utils.CheckError(err)
utils.CheckReturnCode(code, res)
}
示例6: cmdCreate
func cmdCreate(c *cli.Context) {
utils.FlagsRequired(c, []string{"name", "domain_id", "ssh_profile_id", "firewall_profile_id"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
v := make(map[string]string)
v["name"] = c.String("name")
v["domain_id"] = c.String("domain_id")
v["ssh_profile_id"] = c.String("ssh_profile_id")
v["firewall_profile_id"] = c.String("firewall_profile_id")
jsonBytes, err := json.Marshal(v)
utils.CheckError(err)
err, res, code := webservice.Post("/v1/cloud/workspaces", jsonBytes)
if res == nil {
log.Fatal(err)
}
utils.CheckError(err)
utils.CheckReturnCode(code, res)
var workspace Workspace
err = json.Unmarshal(res, &workspace)
utils.CheckError(err)
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tNAME\tDEFAULT\tDOMAIN ID\tSSH PROFILE ID\tFIREWALL PROFILE ID\r")
fmt.Fprintf(w, "%s\t%s\t%t\t%s\t%s\t%s\n", workspace.Id, workspace.Name, workspace.Default, workspace.Domain_id, workspace.Ssh_profile_id, workspace.Firewall_profile_id)
w.Flush()
}
示例7: cmdAddNode
func cmdAddNode(c *cli.Context) {
utils.FlagsRequired(c, []string{"balancer_id", "server_id", "port"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
v := make(map[string]string)
v["server_id"] = c.String("server_id")
v["port"] = c.String("port")
jsonBytes, err := json.Marshal(v)
utils.CheckError(err)
err, res, code := webservice.Post(fmt.Sprintf("/v1/network/load_balancers/%s/nodes", c.String("balancer_id")), jsonBytes)
if res == nil {
log.Fatal(err)
}
utils.CheckError(err)
utils.CheckReturnCode(code, res)
var n Node
err = json.Unmarshal(res, &n)
utils.CheckError(err)
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tNAME\tPUBLIC IP\tSTATE\tSERVER ID\tPORT\r")
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\n", n.Id, n.Name, n.PublicIp, n.State, n.ServerId, n.Port)
w.Flush()
}
示例8: cmdUpdate
func cmdUpdate(c *cli.Context) {
utils.FlagsRequired(c, []string{"id"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
v := make(map[string]string)
if c.IsSet("name") {
v["name"] = c.String("name")
}
if c.IsSet("fqdn") {
v["fqdn"] = c.String("fqdn")
}
jsonBytes, err := json.Marshal(v)
utils.CheckError(err)
err, res, code := webservice.Put(fmt.Sprintf("/v1/cloud/servers/%s", c.String("id")), jsonBytes)
utils.CheckError(err)
utils.CheckReturnCode(code, res)
var server Server
err = json.Unmarshal(res, &server)
utils.CheckError(err)
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tNAME\tFQDN\tSTATE\tPUBLIC IP\tWORKSPACE ID\tTEMPLATE ID\tSERVER PLAN ID\tSSH PROFILE ID\r")
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", server.Id, server.Name, server.Fqdn, server.State, server.Public_ip, server.Workspace_id, server.Template_id, server.Server_plan_id, server.Ssh_profile_id)
w.Flush()
}
示例9: cmdCreate
func cmdCreate(c *cli.Context) {
utils.FlagsRequired(c, []string{"name", "description", "code"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
v := make(map[string]string)
v["name"] = c.String("name")
v["description"] = c.String("description")
v["code"] = c.String("code")
if c.IsSet("parameters") {
v["parameters"] = c.String("parameters")
}
jsonBytes, err := json.Marshal(v)
utils.CheckError(err)
err, res, code := webservice.Post("/v1/blueprint/scripts", jsonBytes)
if res == nil {
log.Fatal(err)
}
utils.CheckError(err)
utils.CheckReturnCode(code, res)
var new_script Script
err = json.Unmarshal(res, &new_script)
utils.CheckError(err)
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tNAME\tDESCRIPTION\tCODE\tPARAMETERS\r")
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", new_script.Id, new_script.Name, new_script.Description, new_script.Code, new_script.Parameters)
w.Flush()
}
示例10: cmdShow
func cmdShow(c *cli.Context) {
var vals LicenseeReport
utils.FlagsRequired(c, []string{"id"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
err, data, res := webservice.Get(fmt.Sprintf("/v1/licensee/reports/%s", c.String("id")))
utils.CheckError(err)
utils.CheckReturnCode(res, data)
err = json.Unmarshal(data, &vals)
utils.CheckError(err)
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprintln(w, "REPORT ID\tYEAR\tMONTH\tSTART TIME\tEND TIME\tSERVER SECONDS\tCLOSED\r")
fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%g\t%t\n", vals.Id, vals.Year, vals.Month, vals.StartTime, vals.EndTime, vals.ServerSeconds, vals.Closed)
fmt.Fprintln(w, "LINES:\r")
fmt.Fprintln(w, "ID\tCOMMISSIONED AT\tDECOMMISSIONED AT\tINSTANCE ID\tINSTANCE NAME\tINSTANCE FQDN\tCONSUMPTION\r")
for _, l := range vals.Li {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%g\n", l.Id, l.Commissioned_at, l.Decommissioned_at, l.Instance_id, l.Instance_name, l.Instance_fqdn, l.Consumption)
}
w.Flush()
}
示例11: cmdDeleteTemplateScript
func cmdDeleteTemplateScript(c *cli.Context) {
utils.FlagsRequired(c, []string{"id", "template_id"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
err, mesg, res := webservice.Delete(fmt.Sprintf("/v1/blueprint/templates/%s/scripts/%s", c.String("template_id"), c.String("id")))
utils.CheckError(err)
utils.CheckReturnCode(res, mesg)
}
示例12: cmdDeleteDomainRecords
func cmdDeleteDomainRecords(c *cli.Context) {
utils.FlagsRequired(c, []string{"domain_id", "id"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
err, mesg, res := webservice.Delete(fmt.Sprintf("/v1/dns/domains/%s/records/%s", c.String("domain_id"), c.String("id")))
utils.CheckError(err)
utils.CheckReturnCode(res, mesg)
}
示例13: cmdDelete
func cmdDelete(c *cli.Context) {
utils.FlagsRequired(c, []string{"id"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
err, mesg, res := webservice.Delete(fmt.Sprintf("/v1/cloud/workspaces/%s", c.String("id")))
utils.CheckError(err)
utils.CheckReturnCode(res, mesg)
}
示例14: cmdDelNode
func cmdDelNode(c *cli.Context) {
utils.FlagsRequired(c, []string{"balancer_id", "node_id"})
webservice, err := webservice.NewWebService()
utils.CheckError(err)
err, mesg, res := webservice.Delete(fmt.Sprintf("/v1/network/load_balancers/%s/nodes/%s", c.String("balancer_id"), c.String("node_id")))
utils.CheckError(err)
utils.CheckReturnCode(res, mesg)
}
示例15: cmdCreate
func cmdCreate(c *cli.Context) {
utils.FlagsRequired(c, []string{"protocol"})
if c.String("protocol") == "https" {
utils.FlagsRequired(c, []string{"name", "fqdn", "protocol", "domain_id", "cloud_provider_id", "ssl_certificate", "ssl_certificate_private_key"})
} else {
utils.FlagsRequired(c, []string{"name", "fqdn", "protocol", "domain_id", "cloud_provider_id"})
}
webservice, err := webservice.NewWebService()
utils.CheckError(err)
v := make(map[string]string)
v["name"] = c.String("name")
v["fqdn"] = c.String("fqdn")
v["protocol"] = strings.ToLower(c.String("protocol"))
v["domain_id"] = c.String("domain_id")
v["cloud_provider_id"] = c.String("cloud_provider_id")
if c.IsSet("ssl_certificate") {
v["ssl_certificate"] = c.String("ssl_certificate")
}
if c.IsSet("ssl_certificate_private_key") {
v["ssl_certificate_private_key"] = c.String("ssl_certificate_private_key")
}
if c.IsSet("port") {
v["port"] = c.String("port")
}
if c.IsSet("algorithm") {
v["algorithm"] = c.String("algorithm")
}
jsonBytes, err := json.Marshal(v)
utils.CheckError(err)
err, res, code := webservice.Post("/v1/network/load_balancers", jsonBytes)
if res == nil {
log.Fatal(err)
}
utils.CheckError(err)
utils.CheckReturnCode(code, res)
var lb LoadBalancer
err = json.Unmarshal(res, &lb)
utils.CheckError(err)
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tNAME\tFQDN\tPROTOCOL\tPORT\tALGORITHM\tSSL CERTIFICATE\tSSL CERTIFICATE PRIVATE KEY\tDOMAIN ID\tCLOUD PROVIDER ID\tTRAFFIC IN\tTRAFFIC OUT\r")
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%d\t%d\n", lb.Id, lb.Name, lb.Fqdn, lb.Protocol, lb.Port, lb.Algorithm, lb.SslCertificate, lb.Ssl_certificate_private_key, lb.Domain_id, lb.Cloud_provider_id, lb.Traffic_in, lb.Traffic_out)
w.Flush()
}