• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang client.Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/deis/deis/client-go/controller/client.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: New

// New adds a domain to an app.
func New(c *client.Client, appID string, domain string) (api.Domain, error) {
	u := fmt.Sprintf("/v1/apps/%s/domains/", appID)

	req := api.DomainCreateRequest{Domain: domain}

	body, err := json.Marshal(req)

	if err != nil {
		return api.Domain{}, err
	}

	resBody, status, err := c.BasicRequest("POST", u, body)

	if err != nil {
		return api.Domain{}, err
	}

	if status != 201 {
		return api.Domain{}, errors.New(resBody)
	}

	res := api.Domain{}
	if err = json.Unmarshal([]byte(resBody), &res); err != nil {
		return api.Domain{}, err
	}

	return res, nil
}
开发者ID:Kazanz,项目名称:deis,代码行数:29,代码来源:domains.go


示例2: New

// New creates a build for an app.
func New(c *client.Client, appID string, image string,
	procfile map[string]string) (api.Build, error) {

	u := fmt.Sprintf("/v1/apps/%s/builds/", appID)

	req := api.CreateBuildRequest{Image: image, Procfile: procfile}

	body, err := json.Marshal(req)

	if err != nil {
		return api.Build{}, err
	}

	resBody, err := c.BasicRequest("POST", u, body)

	if err != nil {
		return api.Build{}, err
	}

	build := api.Build{}
	if err = json.Unmarshal([]byte(resBody), &build); err != nil {
		return api.Build{}, err
	}

	return build, nil
}
开发者ID:laurrentt,项目名称:deis,代码行数:27,代码来源:builds.go


示例3: Rollback

// Rollback rolls back an app to a previous release.
func Rollback(c *client.Client, appID string, version int) (int, error) {
	u := fmt.Sprintf("/v1/apps/%s/releases/rollback/", appID)

	req := api.ReleaseRollback{Version: version}

	var err error
	var reqBody []byte
	if version != -1 {
		reqBody, err = json.Marshal(req)

		if err != nil {
			return -1, err
		}
	}

	body, err := c.BasicRequest("POST", u, reqBody)

	if err != nil {
		return -1, err
	}

	response := api.ReleaseRollback{}

	if err = json.Unmarshal([]byte(body), &response); err != nil {
		return -1, err
	}

	return response.Version, nil
}
开发者ID:laurrentt,项目名称:deis,代码行数:30,代码来源:releases.go


示例4: Set

// Set sets an app's config variables.
func Set(c *client.Client, app string, config api.Config) (api.Config, error) {
	body, err := json.Marshal(config)

	if err != nil {
		return api.Config{}, err
	}

	u := fmt.Sprintf("/v1/apps/%s/config/", app)

	resBody, status, err := c.BasicRequest("POST", u, body)

	if err != nil {
		return api.Config{}, err
	}

	if status != 201 {
		return api.Config{}, errors.New(resBody)
	}

	newConfig := api.Config{}
	if err = json.Unmarshal([]byte(resBody), &newConfig); err != nil {
		return api.Config{}, err
	}

	return newConfig, nil
}
开发者ID:Kazanz,项目名称:deis,代码行数:27,代码来源:config.go


示例5: Restart

// Restart an app's processes.
func Restart(c *client.Client, appID string, procType string, num int) ([]api.Process, error) {
	u := fmt.Sprintf("/v1/apps/%s/containers/", appID)

	if procType == "" {
		u += "restart/"
	} else {
		if num == -1 {
			u += procType + "/restart/"
		} else {
			u += procType + "/" + strconv.Itoa(num) + "/restart/"
		}
	}

	body, err := c.BasicRequest("POST", u, nil)

	if err != nil {
		return []api.Process{}, err
	}

	procs := []api.Process{}
	if err = json.Unmarshal([]byte(body), &procs); err != nil {
		return []api.Process{}, err
	}

	return procs, nil
}
开发者ID:laurrentt,项目名称:deis,代码行数:27,代码来源:ps.go


示例6: New

// New creates a new cert.
func New(c *client.Client, cert string, key string, commonName string) (api.Cert, error) {
	req := api.CertCreateRequest{Certificate: cert, Key: key, Name: commonName}
	reqBody, err := json.Marshal(req)

	if err != nil {
		return api.Cert{}, err
	}

	resBody, status, err := c.BasicRequest("POST", "/v1/certs/", reqBody)

	if err != nil {
		return api.Cert{}, err
	}

	if status != 201 {
		return api.Cert{}, errors.New(resBody)
	}

	resCert := api.Cert{}
	if err = json.Unmarshal([]byte(resBody), &resCert); err != nil {
		return api.Cert{}, err
	}

	return resCert, nil
}
开发者ID:sdgdsffdsfff,项目名称:deis,代码行数:26,代码来源:certs.go


示例7: Regenerate

// Regenerate user's auth tokens.
func Regenerate(c *client.Client, username string, all bool) (string, error) {
	var reqBody []byte
	var err error

	if all == true {
		reqBody, err = json.Marshal(api.AuthRegenerateRequest{All: all})
	} else if username != "" {
		reqBody, err = json.Marshal(api.AuthRegenerateRequest{Name: username})
	}

	if err != nil {
		return "", err
	}

	body, err := c.BasicRequest("POST", "/v1/auth/tokens/", reqBody)

	if err != nil {
		return "", err
	}

	if all == true {
		return "", nil
	}

	token := api.AuthRegenerateResponse{}
	if err = json.Unmarshal([]byte(body), &token); err != nil {
		return "", err
	}

	return token.Token, nil
}
开发者ID:laurrentt,项目名称:deis,代码行数:32,代码来源:auth.go


示例8: New

// New creates a new app.
func New(c *client.Client, id string) (api.App, error) {
	body := []byte{}

	var err error
	if id != "" {
		req := api.AppCreateRequest{ID: id}
		body, err = json.Marshal(req)

		if err != nil {
			return api.App{}, err
		}
	}

	resBody, err := c.BasicRequest("POST", "/v1/apps/", body)

	if err != nil {
		return api.App{}, err
	}

	app := api.App{}
	if err = json.Unmarshal([]byte(resBody), &app); err != nil {
		return api.App{}, err
	}

	return app, nil
}
开发者ID:rsackler,项目名称:deis,代码行数:27,代码来源:apps.go


示例9: Run

// Run one time command in an app.
func Run(c *client.Client, appID string, command string) (api.AppRunResponse, error) {
	req := api.AppRunRequest{Command: command}
	body, err := json.Marshal(req)

	if err != nil {
		return api.AppRunResponse{}, err
	}

	u := fmt.Sprintf("/v1/apps/%s/run", appID)

	resBody, status, err := c.BasicRequest("POST", u, body)

	if err != nil {
		return api.AppRunResponse{}, err
	}

	if status != 200 {
		return api.AppRunResponse{}, errors.New(resBody)
	}

	out := make([]interface{}, 2)

	if err = json.Unmarshal([]byte(resBody), &out); err != nil {
		return api.AppRunResponse{}, err
	}

	return api.AppRunResponse{Output: out[1].(string), ReturnCode: int(out[0].(float64))}, nil
}
开发者ID:Kazanz,项目名称:deis,代码行数:29,代码来源:apps.go


示例10: doList

func doList(c *client.Client, u string) (string, error) {
	body, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return "", err
	}

	return body, nil
}
开发者ID:laurrentt,项目名称:deis,代码行数:9,代码来源:perms.go


示例11: Register

// Register a new user with the controller.
func Register(c *client.Client, username, password, email string) error {
	user := api.AuthRegisterRequest{Username: username, Password: password, Email: email}
	body, err := json.Marshal(user)

	if err != nil {
		return err
	}

	_, err = c.BasicRequest("POST", "/v1/auth/register/", body)
	return err
}
开发者ID:laurrentt,项目名称:deis,代码行数:12,代码来源:auth.go


示例12: Scale

// Scale an app's processes.
func Scale(c *client.Client, appID string, targets map[string]int) error {
	u := fmt.Sprintf("/v1/apps/%s/scale/", appID)

	body, err := json.Marshal(targets)

	if err != nil {
		return err
	}

	_, err = c.BasicRequest("POST", u, body)
	return err
}
开发者ID:laurrentt,项目名称:deis,代码行数:13,代码来源:ps.go


示例13: doDelete

func doDelete(c *client.Client, u string) error {
	body, status, err := c.BasicRequest("DELETE", u, nil)

	if err != nil {
		return err
	}

	if status != 204 {
		return errors.New(body)
	}

	return nil
}
开发者ID:shashankmjain,项目名称:deis,代码行数:13,代码来源:perms.go


示例14: doList

func doList(c *client.Client, u string) (string, error) {
	body, status, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return "", err
	}

	if status != 200 {
		return "", errors.New(body)
	}

	return body, nil
}
开发者ID:shashankmjain,项目名称:deis,代码行数:13,代码来源:perms.go


示例15: Delete

// Delete removes a domain from an app.
func Delete(c *client.Client, appID string, domain string) error {
	u := fmt.Sprintf("/v1/apps/%s/domains/%s", appID, domain)
	body, status, err := c.BasicRequest("DELETE", u, nil)

	if err != nil {
		return err
	}

	if status != 204 {
		return errors.New(body)
	}

	return nil
}
开发者ID:Kazanz,项目名称:deis,代码行数:15,代码来源:domains.go


示例16: List

// List users registered with the controller.
func List(c *client.Client) ([]api.User, error) {
	body, err := c.BasicRequest("GET", "/v1/users/", nil)

	if err != nil {
		return []api.User{}, err
	}

	users := api.Users{}
	if err = json.Unmarshal([]byte(body), &users); err != nil {
		return []api.User{}, err
	}

	return users.Users, nil
}
开发者ID:laurrentt,项目名称:deis,代码行数:15,代码来源:users.go


示例17: List

// List users that can access an app.
func List(c *client.Client, appID string) ([]string, error) {
	body, err := c.BasicRequest("GET", fmt.Sprintf("/v1/apps/%s/perms/", appID), nil)

	if err != nil {
		return []string{}, err
	}

	var users api.PermsAppResponse
	if err = json.Unmarshal([]byte(body), &users); err != nil {
		return []string{}, err
	}

	return users.Users, nil
}
开发者ID:rsackler,项目名称:deis,代码行数:15,代码来源:perms.go


示例18: List

// List users registered with the controller.
func List(c *client.Client, results int) ([]api.User, int, error) {
	body, count, err := c.LimitedRequest("/v1/users/", results)

	if err != nil {
		return []api.User{}, -1, err
	}

	var users []api.User
	if err = json.Unmarshal([]byte(body), &users); err != nil {
		return []api.User{}, -1, err
	}

	return users, count, nil
}
开发者ID:rsackler,项目名称:deis,代码行数:15,代码来源:users.go


示例19: List

// List keys on a controller.
func List(c *client.Client) ([]api.Key, error) {
	body, err := c.BasicRequest("GET", "/v1/keys/", nil)

	if err != nil {
		return []api.Key{}, err
	}

	keys := api.Keys{}
	if err = json.Unmarshal([]byte(body), &keys); err != nil {
		return []api.Key{}, err
	}

	return keys.Keys, nil
}
开发者ID:laurrentt,项目名称:deis,代码行数:15,代码来源:keys.go


示例20: List

// List certs registered with the controller.
func List(c *client.Client) ([]api.Cert, error) {
	body, err := c.BasicRequest("GET", "/v1/certs/", nil)

	if err != nil {
		return []api.Cert{}, err
	}

	res := api.Certs{}
	if err = json.Unmarshal([]byte(body), &res); err != nil {
		return []api.Cert{}, err
	}

	return res.Certs, nil
}
开发者ID:laurrentt,项目名称:deis,代码行数:15,代码来源:certs.go



注:本文中的github.com/deis/deis/client-go/controller/client.Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang api.Config类代码示例发布时间:2022-05-23
下一篇:
Golang client.New函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap