本文整理匯總了Golang中github.com/tsuru/tsuru/provision/docker/bs.Config.UpdateEnvMaps方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.UpdateEnvMaps方法的具體用法?Golang Config.UpdateEnvMaps怎麽用?Golang Config.UpdateEnvMaps使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/tsuru/tsuru/provision/docker/bs.Config
的用法示例。
在下文中一共展示了Config.UpdateEnvMaps方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: bsEnvSetHandler
func bsEnvSetHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error {
var requestConfig bs.Config
err := json.NewDecoder(r.Body).Decode(&requestConfig)
if err != nil {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: fmt.Sprintf("unable to parse body as json: %s", err),
}
}
if len(requestConfig.Envs) > 0 && !permission.Check(t, permission.PermNodeBs) {
return permission.ErrUnauthorized
}
for _, poolEnv := range requestConfig.Pools {
hasPermission := permission.Check(t, permission.PermNodeBs,
permission.Context(permission.CtxPool, poolEnv.Name))
if !hasPermission {
return permission.ErrUnauthorized
}
}
currentConfig, err := bs.LoadConfig(nil)
if err != nil {
if err != mgo.ErrNotFound {
return err
}
currentConfig = &bs.Config{}
}
envMap := bs.EnvMap{}
poolEnvMap := bs.PoolEnvMap{}
err = currentConfig.UpdateEnvMaps(envMap, poolEnvMap)
if err != nil {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: err.Error(),
}
}
err = requestConfig.UpdateEnvMaps(envMap, poolEnvMap)
if err != nil {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: err.Error(),
}
}
err = bs.SaveEnvs(envMap, poolEnvMap)
if err != nil {
return err
}
keepAliveWriter := tsuruIo.NewKeepAliveWriter(w, 15*time.Second, "")
defer keepAliveWriter.Stop()
writer := &tsuruIo.SimpleJsonMessageEncoderWriter{Encoder: json.NewEncoder(keepAliveWriter)}
err = bs.RecreateContainers(mainDockerProvisioner, writer)
if err != nil {
writer.Encode(tsuruIo.SimpleJsonMessage{Error: err.Error()})
}
return nil
}
示例2: bsEnvSetHandler
func bsEnvSetHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error {
var requestConfig bs.Config
err := json.NewDecoder(r.Body).Decode(&requestConfig)
if err != nil {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: fmt.Sprintf("unable to parse body as json: %s", err),
}
}
currentConfig, err := bs.LoadConfig()
if err != nil {
if err != mgo.ErrNotFound {
return err
}
currentConfig = &bs.Config{}
}
envMap := bs.EnvMap{}
poolEnvMap := bs.PoolEnvMap{}
err = currentConfig.UpdateEnvMaps(envMap, poolEnvMap)
if err != nil {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: err.Error(),
}
}
err = requestConfig.UpdateEnvMaps(envMap, poolEnvMap)
if err != nil {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: err.Error(),
}
}
err = bs.SaveEnvs(envMap, poolEnvMap)
if err != nil {
return err
}
keepAliveWriter := tsuruIo.NewKeepAliveWriter(w, 15*time.Second, "")
defer keepAliveWriter.Stop()
writer := &tsuruIo.SimpleJsonMessageEncoderWriter{Encoder: json.NewEncoder(keepAliveWriter)}
err = bs.RecreateContainers(mainDockerProvisioner, writer)
if err != nil {
writer.Encode(tsuruIo.SimpleJsonMessage{Error: err.Error()})
}
return nil
}
示例3: bsEnvSetHandler
func bsEnvSetHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error {
var requestConfig bs.Config
err := json.NewDecoder(r.Body).Decode(&requestConfig)
if err != nil {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: fmt.Sprintf("unable to parse body as json: %s", err),
}
}
currentConfig, err := bs.LoadConfig()
if err != nil {
if err != mgo.ErrNotFound {
return err
}
currentConfig = &bs.Config{}
}
envMap := bs.EnvMap{}
poolEnvMap := bs.PoolEnvMap{}
err = currentConfig.UpdateEnvMaps(envMap, poolEnvMap)
if err != nil {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: err.Error(),
}
}
err = requestConfig.UpdateEnvMaps(envMap, poolEnvMap)
if err != nil {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: err.Error(),
}
}
err = bs.SaveEnvs(envMap, poolEnvMap)
if err != nil {
return err
}
err = bs.RecreateContainers(mainDockerProvisioner)
if err != nil {
return err
}
w.WriteHeader(http.StatusNoContent)
return nil
}