本文整理汇总了Golang中github.com/tsuru/tsuru/provision/docker/bs.Config类的典型用法代码示例。如果您正苦于以下问题:Golang Config类的具体用法?Golang Config怎么用?Golang Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的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
}
开发者ID:reoring,项目名称:tsuru,代码行数:55,代码来源:handlers.go
示例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
}
开发者ID:nikolasmagno,项目名称:tsuru,代码行数:45,代码来源:handlers.go
示例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
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:43,代码来源:handlers.go
注:本文中的github.com/tsuru/tsuru/provision/docker/bs.Config类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论