本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/cloudcfg.ResourcePrinter类的典型用法代码示例。如果您正苦于以下问题:Golang ResourcePrinter类的具体用法?Golang ResourcePrinter怎么用?Golang ResourcePrinter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourcePrinter类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: executeAPIRequest
// Attempts to execute an API request
func executeAPIRequest(method string, auth *kube_client.AuthInfo) bool {
parseStorage := func() string {
if len(flag.Args()) != 2 {
log.Fatal("usage: cloudcfg [OPTIONS] get|list|create|update|delete <url>")
}
return strings.Trim(flag.Arg(1), "/")
}
readUrl := func(storage string) string {
return *httpServer + path.Join("/api/v1beta1", storage)
}
var request *http.Request
var err error
switch method {
case "get", "list":
url := readUrl(parseStorage())
if len(*labelQuery) > 0 && method == "list" {
url = url + "?labels=" + *labelQuery
}
request, err = http.NewRequest("GET", url, nil)
case "delete":
request, err = http.NewRequest("DELETE", readUrl(parseStorage()), nil)
case "create":
storage := parseStorage()
request, err = cloudcfg.RequestWithBodyData(readConfig(storage), readUrl(storage), "POST")
case "update":
storage := parseStorage()
request, err = cloudcfg.RequestWithBodyData(readConfig(storage), readUrl(storage), "PUT")
default:
return false
}
var printer cloudcfg.ResourcePrinter
if *json {
printer = &cloudcfg.IdentityPrinter{}
} else if *yaml {
printer = &cloudcfg.YAMLPrinter{}
} else {
printer = &cloudcfg.HumanReadablePrinter{}
}
var body string
if body, err = cloudcfg.DoRequest(request, auth); err == nil {
if err = printer.Print(body, os.Stdout); err != nil {
log.Fatalf("Failed to print: %#v\nRaw received text:\n%v\n", err, string(body))
}
fmt.Print("\n")
} else {
log.Fatalf("Error: %#v %s", err, body)
}
return true
}
开发者ID:jgeewax,项目名称:kubernetes,代码行数:55,代码来源:cloudcfg.go
示例2: main
// CloudCfg command line tool.
func main() {
flag.Parse() // Scan the arguments list
if *versionFlag {
fmt.Println("Version:", APP_VERSION)
os.Exit(0)
}
if len(flag.Args()) < 2 {
usage()
}
method := flag.Arg(0)
secure := true
parsedUrl, err := url.Parse(*httpServer)
if err != nil {
log.Fatalf("Unable to parse %v as a URL\n", err)
}
if parsedUrl.Scheme != "" && parsedUrl.Scheme != "https" {
secure = false
}
storage := strings.Trim(flag.Arg(1), "/")
url := *httpServer + path.Join("/api/v1beta1", storage)
var request *http.Request
var printer cloudcfg.ResourcePrinter
if *json {
printer = &cloudcfg.IdentityPrinter{}
} else if *yaml {
printer = &cloudcfg.YAMLPrinter{}
} else {
printer = &cloudcfg.HumanReadablePrinter{}
}
var auth *kube_client.AuthInfo
if secure {
auth, err = cloudcfg.LoadAuthInfo(*authConfig)
if err != nil {
log.Fatalf("Error loading auth: %#v", err)
}
}
switch method {
case "get", "list":
if len(*labelQuery) > 0 && method == "list" {
url = url + "?labels=" + *labelQuery
}
request, err = http.NewRequest("GET", url, nil)
case "delete":
request, err = http.NewRequest("DELETE", url, nil)
case "create":
request, err = cloudcfg.RequestWithBodyData(readConfig(storage), url, "POST")
case "update":
request, err = cloudcfg.RequestWithBodyData(readConfig(storage), url, "PUT")
case "rollingupdate":
client := &kube_client.Client{
Host: *httpServer,
Auth: auth,
}
cloudcfg.Update(flag.Arg(1), client, *updatePeriod)
case "run":
args := flag.Args()
if len(args) < 4 {
log.Fatal("usage: cloudcfg -h <host> run <image> <replicas> <name>")
}
image := args[1]
replicas, err := strconv.Atoi(args[2])
name := args[3]
if err != nil {
log.Fatalf("Error parsing replicas: %#v", err)
}
err = cloudcfg.RunController(image, name, replicas, kube_client.Client{Host: *httpServer, Auth: auth}, *portSpec, *servicePort)
if err != nil {
log.Fatalf("Error: %#v", err)
}
return
case "stop":
err = cloudcfg.StopController(flag.Arg(1), kube_client.Client{Host: *httpServer, Auth: auth})
if err != nil {
log.Fatalf("Error: %#v", err)
}
return
case "rm":
err = cloudcfg.DeleteController(flag.Arg(1), kube_client.Client{Host: *httpServer, Auth: auth})
if err != nil {
log.Fatalf("Error: %#v", err)
}
return
default:
log.Fatalf("Unknown command: %s", method)
}
if err != nil {
log.Fatalf("Error: %#v", err)
}
body, err := cloudcfg.DoRequest(request, auth)
if err != nil {
log.Fatalf("Error: %#v", err)
}
err = printer.Print(body, os.Stdout)
if err != nil {
//.........这里部分代码省略.........
开发者ID:jay-potter,项目名称:kubernetes,代码行数:101,代码来源:cloudcfg.go
示例3: main
// CloudCfg command line tool.
func main() {
flag.Parse() // Scan the arguments list
if *versionFlag {
fmt.Println("Version:", APP_VERSION)
os.Exit(0)
}
if len(flag.Args()) < 2 {
usage()
}
method := flag.Arg(0)
url := *httpServer + "/api/v1beta1" + flag.Arg(1)
var request *http.Request
var err error
var printer cloudcfg.ResourcePrinter
if *json {
printer = &cloudcfg.IdentityPrinter{}
} else if *yaml {
printer = &cloudcfg.YAMLPrinter{}
} else {
printer = &cloudcfg.HumanReadablePrinter{}
}
auth, err := cloudcfg.LoadAuthInfo(*authConfig)
if err != nil {
log.Fatalf("Error loading auth: %#v", err)
}
if method == "get" || method == "list" {
if len(*labelQuery) > 0 && method == "list" {
url = url + "?labels=" + *labelQuery
}
request, err = http.NewRequest("GET", url, nil)
} else if method == "delete" {
request, err = http.NewRequest("DELETE", url, nil)
} else if method == "create" {
request, err = cloudcfg.RequestWithBody(*config, url, "POST")
} else if method == "update" {
request, err = cloudcfg.RequestWithBody(*config, url, "PUT")
} else if method == "rollingupdate" {
client := &kube_client.Client{
Host: *httpServer,
Auth: &auth,
}
cloudcfg.Update(flag.Arg(1), client, *updatePeriod)
} else if method == "run" {
args := flag.Args()
if len(args) < 4 {
log.Fatal("usage: cloudcfg -h <host> run <image> <replicas> <name>")
}
image := args[1]
replicas, err := strconv.Atoi(args[2])
name := args[3]
if err != nil {
log.Fatalf("Error parsing replicas: %#v", err)
}
err = cloudcfg.RunController(image, name, replicas, kube_client.Client{Host: *httpServer, Auth: &auth}, *portSpec, *servicePort)
if err != nil {
log.Fatalf("Error: %#v", err)
}
return
} else if method == "stop" {
err = cloudcfg.StopController(flag.Arg(1), kube_client.Client{Host: *httpServer, Auth: &auth})
if err != nil {
log.Fatalf("Error: %#v", err)
}
return
} else if method == "rm" {
err = cloudcfg.DeleteController(flag.Arg(1), kube_client.Client{Host: *httpServer, Auth: &auth})
if err != nil {
log.Fatalf("Error: %#v", err)
}
return
} else {
log.Fatalf("Unknown command: %s", method)
}
if err != nil {
log.Fatalf("Error: %#v", err)
}
var body string
body, err = cloudcfg.DoRequest(request, auth.User, auth.Password)
if err != nil {
log.Fatalf("Error: %#v", err)
}
err = printer.Print(body, os.Stdout)
if err != nil {
log.Fatalf("Failed to print: %#v", err)
}
fmt.Print("\n")
}
开发者ID:nivertech,项目名称:kubernetes,代码行数:93,代码来源:cloudcfg.go
注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/cloudcfg.ResourcePrinter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论