本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/errors.NewWithFmt函数的典型用法代码示例。如果您正苦于以下问题:Golang NewWithFmt函数的具体用法?Golang NewWithFmt怎么用?Golang NewWithFmt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewWithFmt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ParseVersion
func ParseVersion(input string) (Version, error) {
parts := strings.Split(input, ".")
if len(parts) != 3 {
return Version{}, errors.NewWithFmt("Could not parse version number: %s", input)
}
major, err1 := strconv.ParseUint(parts[0], 10, 64)
minor, err2 := strconv.ParseUint(parts[1], 10, 64)
patch, err3 := strconv.ParseUint(parts[2], 10, 64)
if err1 != nil || err2 != nil || err3 != nil {
return Version{}, errors.NewWithFmt("Could not parse version number: %s", input)
}
return Version{major, minor, patch}, nil
}
开发者ID:palakmathur,项目名称:cli,代码行数:15,代码来源:version.go
示例2: createBuildpack
func (cmd CreateBuildpack) createBuildpack(buildpackName string, c *cli.Context) (buildpack models.Buildpack, apiErr error) {
position, err := strconv.Atoi(c.Args()[2])
if err != nil {
apiErr = errors.NewWithFmt(T("Error {{.ErrorDescription}} is being passed in as the argument for 'Position' but 'Position' requires an integer. For more syntax help, see `cf create-buildpack -h`.", map[string]interface{}{"ErrorDescription": c.Args()[2]}))
return
}
enabled := c.Bool("enable")
disabled := c.Bool("disable")
if enabled && disabled {
apiErr = errors.New(T("Cannot specify both {{.Enabled}} and {{.Disabled}}.", map[string]interface{}{
"Enabled": "enabled",
"Disabled": "disabled",
}))
return
}
var enableOption *bool = nil
if enabled {
enableOption = &enabled
}
if disabled {
disabled = false
enableOption = &disabled
}
buildpack, apiErr = cmd.buildpackRepo.Create(buildpackName, &position, enableOption, nil)
return
}
开发者ID:tools-alexuser01,项目名称:cli,代码行数:30,代码来源:create_buildpack.go
示例3: envVarOrEmptyMap
func envVarOrEmptyMap(yamlMap generic.Map, errs *[]error) *map[string]interface{} {
key := "env"
switch envVars := yamlMap.Get(key).(type) {
case nil:
aMap := make(map[string]interface{}, 0)
return &aMap
case map[string]interface{}:
yamlMap.Set(key, generic.NewMap(yamlMap.Get(key)))
return envVarOrEmptyMap(yamlMap, errs)
case map[interface{}]interface{}:
yamlMap.Set(key, generic.NewMap(yamlMap.Get(key)))
return envVarOrEmptyMap(yamlMap, errs)
case generic.Map:
merrs := validateEnvVars(envVars)
if merrs != nil {
*errs = append(*errs, merrs...)
return nil
}
result := make(map[string]interface{}, envVars.Count())
generic.Each(envVars, func(key, value interface{}) {
result[key.(string)] = value
})
return &result
default:
*errs = append(*errs, errors.NewWithFmt(T("Expected {{.Name}} to be a set of key => value, but it was a {{.Type}}.",
map[string]interface{}{"Name": key, "Type": envVars})))
return nil
}
}
开发者ID:tools-alexuser01,项目名称:cli,代码行数:31,代码来源:manifest.go
示例4: createBuildpack
func (cmd CreateBuildpack) createBuildpack(buildpackName string, c *cli.Context) (buildpack models.Buildpack, apiErr error) {
position, err := strconv.Atoi(c.Args()[2])
if err != nil {
apiErr = errors.NewWithFmt("Invalid position. %s", err.Error())
return
}
enabled := c.Bool("enable")
disabled := c.Bool("disable")
if enabled && disabled {
apiErr = errors.New("Cannot specify both enabled and disabled.")
return
}
var enableOption *bool = nil
if enabled {
enableOption = &enabled
}
if disabled {
disabled = false
enableOption = &disabled
}
buildpack, apiErr = cmd.buildpackRepo.Create(buildpackName, &position, enableOption, nil)
return
}
开发者ID:palakmathur,项目名称:cli,代码行数:27,代码来源:create_buildpack.go
示例5: createBuildpack
func (cmd CreateBuildpack) createBuildpack(buildpackName string, c *cli.Context) (buildpack models.Buildpack, apiErr error) {
position, err := strconv.Atoi(c.Args()[2])
if err != nil {
apiErr = errors.NewWithFmt(T("Invalid position. {{.ErrorDescription}}", map[string]interface{}{"ErrorDescription": err.Error()}))
return
}
enabled := c.Bool("enable")
disabled := c.Bool("disable")
if enabled && disabled {
apiErr = errors.New(T("Cannot specify both {{.Enabled}} and {{.Disabled}}.", map[string]interface{}{
"Enabled": "enabled",
"Disabled": "disabled",
}))
return
}
var enableOption *bool = nil
if enabled {
enableOption = &enabled
}
if disabled {
disabled = false
enableOption = &disabled
}
buildpack, apiErr = cmd.buildpackRepo.Create(buildpackName, &position, enableOption, nil)
return
}
开发者ID:raghulsid,项目名称:cli,代码行数:30,代码来源:create_buildpack.go
示例6: intVal
func intVal(yamlMap generic.Map, key string, errs *[]error) *int {
var (
intVal int
err error
)
switch val := yamlMap.Get(key).(type) {
case string:
intVal, err = strconv.Atoi(val)
case int:
intVal = val
case int64:
intVal = int(val)
case nil:
return nil
default:
err = errors.NewWithFmt("Expected %s to be a number, but it was a %T.", key, val)
}
if err != nil {
*errs = append(*errs, err)
return nil
}
return &intVal
}
开发者ID:nandrah,项目名称:cli,代码行数:26,代码来源:manifest.go
示例7: Match
func (matcher havePassedRequirementsMatcher) Match(actual interface{}) (bool, error) {
asBool, ok := actual.(bool)
if !ok {
return false, errors.NewWithFmt("Expected actual value to be a bool, but it was a %T", actual)
}
return asBool == true, nil
}
开发者ID:GABONIA,项目名称:cli,代码行数:8,代码来源:passed_requirements.go
示例8: ParseVersion
func ParseVersion(input string) (Version, error) {
parts := strings.Split(input, ".")
if len(parts) != 3 {
return Version{}, errors.NewWithFmt(T("Could not parse version number: {{.Input}}",
map[string]interface{}{"Input": input}))
}
major, err1 := strconv.ParseInt(parts[0], 10, 64)
minor, err2 := strconv.ParseInt(parts[1], 10, 64)
patch, err3 := strconv.ParseInt(parts[2], 10, 64)
if err1 != nil || err2 != nil || err3 != nil {
return Version{}, errors.NewWithFmt(T("Could not parse version number: {{.Input}}",
map[string]interface{}{"Input": input}))
}
return Version{major, minor, patch}, nil
}
开发者ID:Jack1996,项目名称:cli,代码行数:17,代码来源:version.go
示例9: parseJson
func parseJson(bytes []byte) (map[string]interface{}, error) {
stringMap := map[string]interface{}{}
err := json.Unmarshal(bytes, &stringMap)
if err != nil {
return nil, errors.NewWithFmt("Incorrect json format: %s", err.Error())
}
return stringMap, nil
}
开发者ID:tools-alexuser01,项目名称:cli,代码行数:9,代码来源:json_parser.go
示例10: Match
func (matcher haveSucceededMatcher) Match(actual interface{}) (bool, error) {
switch actual.(type) {
case testcmd.RunCommandResult:
result := actual.(testcmd.RunCommandResult)
return result == testcmd.RunCommandResultSuccess, nil
default:
return false, errors.NewWithFmt("Expected actual value to be an enum, but it was a %T", actual)
}
}
开发者ID:BlueSpice,项目名称:cli,代码行数:9,代码来源:have_succeeded.go
示例11: rolePath
func rolePath(role string) (string, error) {
path, found := orgRoleToPathMap[role]
if !found {
return "", errors.NewWithFmt(T("Invalid Role {{.Role}}",
map[string]interface{}{"Role": role}))
}
return path, nil
}
开发者ID:ArthurHlt,项目名称:cloudfoundry-cli,代码行数:9,代码来源:users.go
示例12: checkSpaceRole
func (repo CloudControllerUserRepository) checkSpaceRole(userGuid, spaceGuid, role string) (fullPath string, apiErr error) {
rolePath, found := spaceRoleToPathMap[role]
if !found {
apiErr = errors.NewWithFmt("Invalid Role %s", role)
}
fullPath = fmt.Sprintf("%s/v2/spaces/%s/%s/%s", repo.config.ApiEndpoint(), spaceGuid, rolePath, userGuid)
return
}
开发者ID:palakmathur,项目名称:cli,代码行数:10,代码来源:users.go
示例13: findAppWithNameInManifest
func findAppWithNameInManifest(name string, manifestApps []models.AppParams) (app models.AppParams, err error) {
for _, appParams := range manifestApps {
if appParams.Name != nil && *appParams.Name == name {
app = appParams
return
}
}
err = errors.NewWithFmt("Could not find app named '%s' in manifest", name)
return
}
开发者ID:palakmathur,项目名称:cli,代码行数:11,代码来源:push.go
示例14: Match
func (matcher havePassedRequirementsMatcher) Match(actual interface{}) (bool, error) {
switch actual.(type) {
case bool:
asBool := actual.(bool)
return asBool == true, nil
case testcmd.RunCommandResult:
result := actual.(testcmd.RunCommandResult)
return result == testcmd.RunCommandResultSuccess, nil
default:
return false, errors.NewWithFmt("Expected actual value to be a bool or enum, but it was a %T", actual)
}
}
开发者ID:BlueSpice,项目名称:cli,代码行数:12,代码来源:passed_requirements.go
示例15: stringVal
func stringVal(yamlMap generic.Map, key string, errs *[]error) *string {
val := yamlMap.Get(key)
if val == nil {
return nil
}
result, ok := val.(string)
if !ok {
*errs = append(*errs, errors.NewWithFmt("%s must be a string value", key))
return nil
}
return &result
}
开发者ID:nandrah,项目名称:cli,代码行数:12,代码来源:manifest.go
示例16: bytesVal
func bytesVal(yamlMap generic.Map, key string, errs *[]error) *uint64 {
yamlVal := yamlMap.Get(key)
if yamlVal == nil {
return nil
}
value, err := formatters.ToMegabytes(yamlVal.(string))
if err != nil {
*errs = append(*errs, errors.NewWithFmt("Unexpected value for %s :\n%s", key, err.Error()))
return nil
}
return &value
}
开发者ID:nandrah,项目名称:cli,代码行数:12,代码来源:manifest.go
示例17: checkForNulls
func checkForNulls(yamlMap generic.Map) (errs []error) {
generic.Each(yamlMap, func(key interface{}, value interface{}) {
if key == "command" || key == "buildpack" {
return
}
if value == nil {
errs = append(errs, errors.NewWithFmt("%s should not be null", key))
}
})
return
}
开发者ID:nandrah,项目名称:cli,代码行数:12,代码来源:manifest.go
示例18: checkSpaceRole
func (repo CloudControllerUserRepository) checkSpaceRole(spaceGuid, role string) (string, error) {
var apiErr error
rolePath, found := spaceRoleToPathMap[role]
if !found {
apiErr = errors.NewWithFmt(T("Invalid Role {{.Role}}",
map[string]interface{}{"Role": role}))
}
apiPath := fmt.Sprintf("/v2/spaces/%s/%s", spaceGuid, rolePath)
return apiPath, apiErr
}
开发者ID:ArthurHlt,项目名称:cloudfoundry-cli,代码行数:13,代码来源:users.go
示例19: boolVal
func boolVal(yamlMap generic.Map, key string, errs *[]error) bool {
switch val := yamlMap.Get(key).(type) {
case nil:
return false
case bool:
return val
case string:
return val == "true"
default:
*errs = append(*errs, errors.NewWithFmt("Expected %s to be a boolean.", key))
return false
}
}
开发者ID:nandrah,项目名称:cli,代码行数:13,代码来源:manifest.go
示例20: setOrganization
func (cmd Target) setOrganization(orgName string) error {
// setting an org necessarily invalidates any space you had previously targeted
cmd.config.SetOrganizationFields(models.OrganizationFields{})
cmd.config.SetSpaceFields(models.SpaceFields{})
org, apiErr := cmd.orgRepo.FindByName(orgName)
if apiErr != nil {
return errors.NewWithFmt("Could not target org.\n%s", apiErr.Error())
}
cmd.config.SetOrganizationFields(org.OrganizationFields)
return nil
}
开发者ID:palakmathur,项目名称:cli,代码行数:13,代码来源:target.go
注:本文中的github.com/cloudfoundry/cli/cf/errors.NewWithFmt函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论