本文整理匯總了Golang中github.com/nttlabs/cli/cf/errors.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: DeleteService
func (repo CloudControllerServiceRepository) DeleteService(instance models.ServiceInstance) (apiErr error) {
if len(instance.ServiceBindings) > 0 {
return errors.New("Cannot delete service instance, apps are still bound to it")
}
path := fmt.Sprintf("%s/v2/service_instances/%s", repo.config.ApiEndpoint(), instance.Guid)
return repo.gateway.DeleteResource(path)
}
示例3: getAuthEndpoint
func (repo CloudControllerUserRepository) getAuthEndpoint() (string, error) {
uaaEndpoint := repo.config.UaaEndpoint()
if uaaEndpoint == "" {
return "", errors.New(T("UAA endpoint missing from config file"))
}
return uaaEndpoint, nil
}
示例4: readAllYAMLFiles
func (repo ManifestDiskRepository) readAllYAMLFiles(path string) (mergedMap generic.Map, err error) {
file, err := os.Open(filepath.Clean(path))
if err != nil {
return
}
defer file.Close()
mapp, err := parseManifest(file)
if err != nil {
return
}
if !mapp.Has("inherit") {
mergedMap = mapp
return
}
inheritedPath, ok := mapp.Get("inherit").(string)
if !ok {
err = errors.New(T("invalid inherit path in manifest"))
return
}
if !filepath.IsAbs(inheritedPath) {
inheritedPath = filepath.Join(filepath.Dir(path), inheritedPath)
}
inheritedMap, err := repo.readAllYAMLFiles(inheritedPath)
if err != nil {
return
}
mergedMap = generic.DeepMerge(inheritedMap, mapp)
return
}
示例5: getAppMaps
func (m Manifest) getAppMaps(data generic.Map) (apps []generic.Map, errs []error) {
globalProperties := data.Except([]interface{}{"applications"})
if data.Has("applications") {
appMaps, ok := data.Get("applications").([]interface{})
if !ok {
errs = append(errs, errors.New(T("Expected applications to be a list")))
return
}
for _, appData := range appMaps {
if !generic.IsMappable(appData) {
errs = append(errs, errors.NewWithFmt(T("Expected application to be a list of key/value pairs\nError occurred in manifest near:\n'{{.YmlSnippet}}'",
map[string]interface{}{"YmlSnippet": appData})))
continue
}
appMap := generic.DeepMerge(globalProperties, generic.NewMap(appData))
apps = append(apps, appMap)
}
} else {
apps = append(apps, globalProperties)
}
return
}
示例6: waitForJob
func (gateway Gateway) waitForJob(jobUrl, accessToken string, timeout time.Duration) (err error) {
startTime := gateway.Clock()
for true {
if gateway.Clock().Sub(startTime) > timeout && timeout != 0 {
return errors.NewAsyncTimeoutError(jobUrl)
}
var request *Request
request, err = gateway.NewRequest("GET", jobUrl, accessToken, nil)
response := &JobResource{}
_, err = gateway.PerformRequestForJSONResponse(request, response)
if err != nil {
return
}
switch response.Entity.Status {
case JOB_FINISHED:
return
case JOB_FAILED:
err = errors.New(response.Entity.ErrorDetails.Description)
return
}
accessToken = request.HttpReq.Header.Get("Authorization")
time.Sleep(gateway.PollingThrottle)
}
return
}
示例7: UploadBuildpack
func (repo *FakeBuildpackBitsRepository) UploadBuildpack(buildpack models.Buildpack, dir string) error {
if repo.UploadBuildpackErr {
return errors.New("Invalid buildpack")
}
repo.UploadBuildpackPath = dir
return repo.UploadBuildpackApiResponse
}
示例8: Update
func (repo *FakeZoneRepository) Update(zoneGuid string, params models.ZoneParams) (apiErr error) {
repo.UpdateZoneGuid = zoneGuid
repo.UpdateZoneParams = params
if repo.UpdateErr {
apiErr = errors.New("Error updating zone.")
}
return
}
示例9: normalizeBuildpackArchive
func normalizeBuildpackArchive(inputFile *os.File, outputFile *os.File) error {
stats, err := inputFile.Stat()
if err != nil {
return err
}
reader, err := zip.NewReader(inputFile, stats.Size())
if err != nil {
return err
}
contents := reader.File
parentPath, hasBuildpack := findBuildpackPath(contents)
if !hasBuildpack {
return errors.New(T("Zip archive does not contain a buildpack"))
}
writer := zip.NewWriter(outputFile)
for _, file := range contents {
name := file.Name
if strings.HasPrefix(name, parentPath) {
relativeFilename := strings.TrimPrefix(name, parentPath+"/")
if relativeFilename == "" {
continue
}
fileInfo := file.FileInfo()
header, err := zip.FileInfoHeader(fileInfo)
if err != nil {
return err
}
header.Name = relativeFilename
w, err := writer.CreateHeader(header)
if err != nil {
return err
}
r, err := file.Open()
if err != nil {
return err
}
io.Copy(w, r)
err = r.Close()
if err != nil {
return err
}
}
}
writer.Close()
outputFile.Seek(0, 0)
return nil
}
示例10: Update
func (repo *FakeApplicationRepository) Update(appGuid string, params models.AppParams) (updatedApp models.Application, apiErr error) {
repo.UpdateAppGuid = appGuid
repo.UpdateParams = params
updatedApp = repo.UpdateAppResult
if repo.UpdateErr {
apiErr = errors.New("Error updating app.")
}
return
}
示例11: validateEnvVars
func validateEnvVars(input generic.Map) (errs []error) {
generic.Each(input, func(key, value interface{}) {
if value == nil {
errs = append(errs, errors.New(fmt.Sprintf(T("env var '{{.PropertyName}}' should not be null",
map[string]interface{}{"PropertyName": key}))))
}
})
return
}
示例12: PrepareRedirect
func PrepareRedirect(req *http.Request, via []*http.Request) error {
if len(via) > 1 {
return errors.New(T("stopped after 1 redirect"))
}
prevReq := via[len(via)-1]
req.Header.Set("Authorization", prevReq.Header.Get("Authorization"))
dumpRequest(req)
return nil
}
示例13: UpdateServiceInstance
func (repo *FakeServiceRepo) UpdateServiceInstance(instanceGuid, planGuid string) (apiErr error) {
if repo.UpdateServiceInstanceReturnsErr {
apiErr = errors.New("Error updating service instance")
} else {
repo.UpdateServiceInstanceArgs.InstanceGuid = instanceGuid
repo.UpdateServiceInstanceArgs.PlanGuid = planGuid
}
return
}
示例14: addApp
func addApp(apps *[]models.AppParams, app models.AppParams) (err error) {
if app.Name == nil {
err = errors.New(T("App name is a required field"))
}
if app.Path == nil {
cwd, _ := os.Getwd()
app.Path = &cwd
}
*apps = append(*apps, app)
return
}
示例15: UpdatePassword
func (repo CloudControllerPasswordRepository) UpdatePassword(old string, new string) error {
uaaEndpoint := repo.config.UaaEndpoint()
if uaaEndpoint == "" {
return errors.New(T("UAA endpoint missing from config file"))
}
url := fmt.Sprintf("%s/Users/%s/password", uaaEndpoint, repo.config.UserGuid())
body := fmt.Sprintf(`{"password":"%s","oldPassword":"%s"}`, new, old)
return repo.gateway.UpdateResource(url, strings.NewReader(body))
}