github.com/naphatkrit/deis@v1.12.3/client/controller/models/config/config.go (about)

     1  package config
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	"github.com/deis/deis/client/controller/api"
     8  	"github.com/deis/deis/client/controller/client"
     9  )
    10  
    11  // List lists an app's config.
    12  func List(c *client.Client, app string) (api.Config, error) {
    13  	u := fmt.Sprintf("/v1/apps/%s/config/", app)
    14  
    15  	body, err := c.BasicRequest("GET", u, nil)
    16  
    17  	if err != nil {
    18  		return api.Config{}, err
    19  	}
    20  
    21  	config := api.Config{}
    22  	if err = json.Unmarshal([]byte(body), &config); err != nil {
    23  		return api.Config{}, err
    24  	}
    25  
    26  	return config, nil
    27  }
    28  
    29  // Set sets an app's config variables.
    30  func Set(c *client.Client, app string, config api.Config) (api.Config, error) {
    31  	body, err := json.Marshal(config)
    32  
    33  	if err != nil {
    34  		return api.Config{}, err
    35  	}
    36  
    37  	u := fmt.Sprintf("/v1/apps/%s/config/", app)
    38  
    39  	resBody, err := c.BasicRequest("POST", u, body)
    40  
    41  	if err != nil {
    42  		return api.Config{}, err
    43  	}
    44  
    45  	newConfig := api.Config{}
    46  	if err = json.Unmarshal([]byte(resBody), &newConfig); err != nil {
    47  		return api.Config{}, err
    48  	}
    49  
    50  	return newConfig, nil
    51  }