本文整理汇总了Golang中github.com/deis/deis/client/controller/client.Client.BasicRequest方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.BasicRequest方法的具体用法?Golang Client.BasicRequest怎么用?Golang Client.BasicRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/deis/deis/client/controller/client.Client
的用法示例。
在下文中一共展示了Client.BasicRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: 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
}
示例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
}
示例6: 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
}
示例7: 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
}
示例8: Transfer
// Transfer an app to another user.
func Transfer(c *client.Client, appID string, username string) error {
u := fmt.Sprintf("/v1/apps/%s/", appID)
req := api.AppUpdateRequest{Owner: username}
body, err := json.Marshal(req)
if err != nil {
return err
}
_, err = c.BasicRequest("POST", u, body)
return err
}
示例9: 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
}
示例10: Logs
// Logs retrieves logs from an app.
func Logs(c *client.Client, appID string, lines int) (string, error) {
u := fmt.Sprintf("/v1/apps/%s/logs", appID)
if lines > 0 {
u += "?log_lines=" + strconv.Itoa(lines)
}
body, err := c.BasicRequest("GET", u, nil)
if err != nil {
return "", err
}
return strings.Trim(body, `"`), nil
}
示例11: Get
// Get a release of an app.
func Get(c *client.Client, appID string, version int) (api.Release, error) {
u := fmt.Sprintf("/v1/apps/%s/releases/v%d/", appID, version)
body, err := c.BasicRequest("GET", u, nil)
if err != nil {
return api.Release{}, err
}
release := api.Release{}
if err = json.Unmarshal([]byte(body), &release); err != nil {
return api.Release{}, err
}
return release, nil
}
示例12: Passwd
// Passwd changes a user's password.
func Passwd(c *client.Client, username, password, newPassword string) error {
req := api.AuthPasswdRequest{Password: password, NewPassword: newPassword}
if username != "" {
req.Username = username
}
body, err := json.Marshal(req)
if err != nil {
return err
}
_, err = c.BasicRequest("POST", "/v1/auth/passwd/", body)
return err
}
示例13: Delete
// Delete deletes a user.
func Delete(c *client.Client, username string) error {
var body []byte
var err error
if username != "" {
req := api.AuthCancelRequest{Username: username}
body, err = json.Marshal(req)
if err != nil {
return err
}
}
_, err = c.BasicRequest("DELETE", "/v1/auth/cancel/", body)
return err
}
示例14: List
// List lists an app's config.
func List(c *client.Client, app string) (api.Config, error) {
u := fmt.Sprintf("/v1/apps/%s/config/", app)
body, err := c.BasicRequest("GET", u, nil)
if err != nil {
return api.Config{}, err
}
config := api.Config{}
if err = json.Unmarshal([]byte(body), &config); err != nil {
return api.Config{}, err
}
return config, nil
}
示例15: Get
// Get app details from a Deis controller.
func Get(c *client.Client, appID string) (api.App, error) {
u := fmt.Sprintf("/v1/apps/%s/", appID)
body, err := c.BasicRequest("GET", u, nil)
if err != nil {
return api.App{}, err
}
app := api.App{}
if err = json.Unmarshal([]byte(body), &app); err != nil {
return api.App{}, err
}
return app, nil
}