• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang errors.Errorf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/errors.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Errorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: DiskPool

func (d Manifest) DiskPool(jobName string) (DiskPool, error) {
	job, found := d.FindJobByName(jobName)
	if !found {
		return DiskPool{}, bosherr.Errorf("Could not find job with name: %s", jobName)
	}

	if job.PersistentDiskPool != "" {
		for _, diskPool := range d.DiskPools {
			if diskPool.Name == job.PersistentDiskPool {
				return diskPool, nil
			}
		}
		err := bosherr.Errorf("Could not find persistent disk pool '%s' for job '%s'", job.PersistentDiskPool, jobName)
		return DiskPool{}, err
	}

	if job.PersistentDisk > 0 {
		diskPool := DiskPool{
			DiskSize:        job.PersistentDisk,
			CloudProperties: biproperty.Map{},
		}
		return diskPool, nil
	}

	return DiskPool{}, nil
}
开发者ID:hanzhefeng,项目名称:bosh-init,代码行数:26,代码来源:manifest.go


示例2: createAllInstances

func (d *deployer) createAllInstances(
	deploymentManifest bideplmanifest.Manifest,
	instanceManager biinstance.Manager,
	cloudStemcell bistemcell.CloudStemcell,
	registryConfig biinstallmanifest.Registry,
	deployStage biui.Stage,
) ([]biinstance.Instance, []bidisk.Disk, error) {
	instances := []biinstance.Instance{}
	disks := []bidisk.Disk{}

	if len(deploymentManifest.Jobs) != 1 {
		return instances, disks, bosherr.Errorf("There must only be one job, found %d", len(deploymentManifest.Jobs))
	}

	for _, jobSpec := range deploymentManifest.Jobs {
		if jobSpec.Instances != 1 {
			return instances, disks, bosherr.Errorf("Job '%s' must have only one instance, found %d", jobSpec.Name, jobSpec.Instances)
		}
		for instanceID := 0; instanceID < jobSpec.Instances; instanceID++ {
			instance, instanceDisks, err := instanceManager.Create(jobSpec.Name, instanceID, deploymentManifest, cloudStemcell, registryConfig, deployStage)
			if err != nil {
				return instances, disks, bosherr.WrapErrorf(err, "Creating instance '%s/%d'", jobSpec.Name, instanceID)
			}
			instances = append(instances, instance)
			disks = append(disks, instanceDisks...)

			err = instance.UpdateJobs(deploymentManifest, deployStage)
			if err != nil {
				return instances, disks, err
			}
		}
	}

	return instances, disks, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:35,代码来源:deployer.go


示例3: Build

// Build creates a generic property that may be a Map, List or primitive.
// If it is a Map or List it will be built using the appropriate builder and constraints.
func Build(val interface{}) (Property, error) {
	if val == nil {
		return nil, nil
	}

	switch reflect.TypeOf(val).Kind() {
	case reflect.Map:
		valMap, ok := val.(map[interface{}]interface{})
		if !ok {
			return nil, bosherr.Errorf("Converting map %#v", val)
		}

		return BuildMap(valMap)

	case reflect.Slice:
		valSlice, ok := val.([]interface{})
		if !ok {
			return nil, bosherr.Errorf("Converting slice %#v", val)
		}

		return BuildList(valSlice)

	default:
		return val, nil
	}
}
开发者ID:vestel,项目名称:bosh-init,代码行数:28,代码来源:builders.go


示例4: validateGateway

func (v *validator) validateGateway(idx int, gateway string, ipNet maybeIPNet) []error {
	if v.isBlank(gateway) {
		return []error{bosherr.Errorf("networks[%d].subnets[0].gateway must be provided", idx)}
	} else {
		errors := []error{}
		ipNet.Try(func(ipNet *net.IPNet) error {
			gatewayIp := net.ParseIP(gateway)
			if gatewayIp == nil {
				errors = append(errors, bosherr.Errorf("networks[%d].subnets[0].gateway must be an ip", idx))
			}

			if !ipNet.Contains(gatewayIp) {
				errors = append(errors, bosherr.Errorf("subnet gateway '%s' must be within the specified range '%s'", gateway, ipNet))
			}

			if ipNet.IP.Equal(gatewayIp) {
				errors = append(errors, bosherr.Errorf("subnet gateway can't be the network address '%s'", gatewayIp))
			}

			if binet.LastAddress(ipNet).Equal(gatewayIp) {
				errors = append(errors, bosherr.Errorf("subnet gateway can't be the broadcast address '%s'", gatewayIp))
			}

			return nil
		})

		return errors
	}
}
开发者ID:vestel,项目名称:bosh-init,代码行数:29,代码来源:validator.go


示例5: validateNetwork

func (v *validator) validateNetwork(network Network, networkIdx int) []error {
	errs := []error{}

	if v.isBlank(network.Name) {
		errs = append(errs, bosherr.Errorf("networks[%d].name must be provided", networkIdx))
	}
	if network.Type != Dynamic && network.Type != Manual && network.Type != VIP {
		errs = append(errs, bosherr.Errorf("networks[%d].type must be 'manual', 'dynamic', or 'vip'", networkIdx))
	}
	if network.Type == Manual {
		if len(network.Subnets) != 1 {
			errs = append(errs, bosherr.Errorf("networks[%d].subnets must be of size 1", networkIdx))
		} else {
			ipRange := network.Subnets[0].Range
			rangeErrors, maybeIpNet := v.validateRange(networkIdx, ipRange)
			errs = append(errs, rangeErrors...)

			gateway := network.Subnets[0].Gateway
			gatewayErrors := v.validateGateway(networkIdx, gateway, maybeIpNet)
			errs = append(errs, gatewayErrors...)
		}
	}

	return errs
}
开发者ID:vestel,项目名称:bosh-init,代码行数:25,代码来源:validator.go


示例6: GetPrimaryIPv4

func (r ipResolver) GetPrimaryIPv4(interfaceName string) (*gonet.IPNet, error) {
	addrs, err := r.ifaceToAddrsFunc(interfaceName)
	if err != nil {
		return nil, bosherr.WrapErrorf(err, "Looking up addresses for interface '%s'", interfaceName)
	}

	if len(addrs) == 0 {
		return nil, bosherr.Errorf("No addresses found for interface '%s'", interfaceName)
	}

	for _, addr := range addrs {
		ip, ok := addr.(*gonet.IPNet)
		if !ok {
			continue
		}

		// ignore ipv6
		if ip.IP.To4() == nil {
			continue
		}

		return ip, nil
	}

	return nil, bosherr.Errorf("Failed to find primary IPv4 address for interface '%s'", interfaceName)
}
开发者ID:vestel,项目名称:bosh-init,代码行数:26,代码来源:ip_resolver.go


示例7: Partition

func (p rootDevicePartitioner) Partition(devicePath string, partitions []Partition) error {
	existingPartitions, deviceFullSizeInBytes, err := p.getPartitions(devicePath)
	if err != nil {
		return bosherr.WrapErrorf(err, "Getting existing partitions of `%s'", devicePath)
	}
	p.logger.Debug(p.logTag, "Current partitions: %#v", existingPartitions)

	if len(existingPartitions) == 0 {
		return bosherr.Errorf("Missing first partition on `%s'", devicePath)
	}

	if p.partitionsMatch(existingPartitions[1:], partitions) {
		p.logger.Info(p.logTag, "Partitions already match, skipping partitioning")
		return nil
	}

	if len(existingPartitions) > 1 {
		p.logger.Error(p.logTag,
			"Failed to create ephemeral partitions on root device `%s'. Expected 1 partition, found %d: %s",
			devicePath,
			len(existingPartitions),
			existingPartitions,
		)
		return bosherr.Errorf("Found %d unexpected partitions on `%s'", len(existingPartitions)-1, devicePath)
	}

	// To support optimal reads on HDDs and optimal erasure on SSD: use 1MiB partition alignments.
	alignmentInBytes := uint64(1048576)

	partitionStart := p.roundUp(existingPartitions[0].EndInBytes+1, alignmentInBytes)

	for index, partition := range partitions {
		partitionEnd := partitionStart + partition.SizeInBytes - 1
		if partitionEnd >= deviceFullSizeInBytes {
			partitionEnd = deviceFullSizeInBytes - 1
			p.logger.Info(p.logTag, "Partition %d would be larger than remaining space. Reducing size to %dB", index, partitionEnd-partitionStart)
		}

		p.logger.Info(p.logTag, "Creating partition %d with start %dB and end %dB", index, partitionStart, partitionEnd)

		_, _, _, err := p.cmdRunner.RunCommand(
			"parted",
			"-s",
			devicePath,
			"unit",
			"B",
			"mkpart",
			"primary",
			fmt.Sprintf("%d", partitionStart),
			fmt.Sprintf("%d", partitionEnd),
		)

		if err != nil {
			return bosherr.WrapErrorf(err, "Partitioning disk `%s'", devicePath)
		}

		partitionStart = p.roundUp(partitionEnd+1, alignmentInBytes)
	}
	return nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:60,代码来源:root_device_partitioner.go


示例8: NewWatchTime

func NewWatchTime(timeRange string) (WatchTime, error) {
	parts := strings.Split(timeRange, "-")
	if len(parts) != 2 {
		return WatchTime{}, bosherr.Errorf("Invalid watch time range '%s'", timeRange)
	}

	start, err := strconv.Atoi(strings.Trim(parts[0], " "))
	if err != nil {
		return WatchTime{}, bosherr.WrapErrorf(
			err, "Non-positive number as watch time minimum %s", parts[0])
	}

	end, err := strconv.Atoi(strings.Trim(parts[1], " "))
	if err != nil {
		return WatchTime{}, bosherr.WrapErrorf(
			err, "Non-positive number as watch time maximum %s", parts[1])
	}

	if end < start {
		return WatchTime{}, bosherr.Errorf(
			"Watch time must have maximum greater than or equal minimum %s", timeRange)
	}

	return WatchTime{
		Start: start,
		End:   end,
	}, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:28,代码来源:watch_time.go


示例9: validateJobNetworks

func (v *validator) validateJobNetworks(jobNetworks []JobNetwork, networks []Network, jobIdx int) []error {
	errs := []error{}
	defaultCounts := make(map[NetworkDefault]int)

	for networkIdx, jobNetwork := range jobNetworks {

		if v.isBlank(jobNetwork.Name) {
			errs = append(errs, bosherr.Errorf("jobs[%d].networks[%d].name must be provided", jobIdx, networkIdx))
		}

		var matchingNetwork Network
		found := false
		for _, network := range networks {
			if network.Name == jobNetwork.Name {
				found = true
				matchingNetwork = network
			}
		}

		if !found {
			errs = append(errs, bosherr.Errorf("jobs[%d].networks[%d] not found in networks", jobIdx, networkIdx))
		}

		for ipIdx, ip := range jobNetwork.StaticIPs {
			staticIPErrors := v.validateStaticIP(ip, jobNetwork, matchingNetwork, jobIdx, networkIdx, ipIdx)
			errs = append(errs, staticIPErrors...)
		}

		for defaultIdx, value := range jobNetwork.Defaults {
			if value != NetworkDefaultDNS && value != NetworkDefaultGateway {
				errs = append(errs, bosherr.Errorf("jobs[%d].networks[%d].default[%d] must be 'dns' or 'gateway'", jobIdx, networkIdx, defaultIdx))
			}
		}

		for _, dflt := range jobNetwork.Defaults {
			count, present := defaultCounts[dflt]
			if present {
				defaultCounts[dflt] = count + 1
			} else {
				defaultCounts[dflt] = 1
			}
		}
	}
	for _, dflt := range []NetworkDefault{"dns", "gateway"} {
		count, found := defaultCounts[dflt]
		if len(jobNetworks) > 1 && !found {
			errs = append(errs, bosherr.Errorf("with multiple networks, a default for '%s' must be specified", dflt))
		} else if count > 1 {
			errs = append(errs, bosherr.Errorf("only one network can be the default for '%s'", dflt))
		}
	}

	return errs
}
开发者ID:vestel,项目名称:bosh-init,代码行数:54,代码来源:validator.go


示例10: validateRange

func (v *validator) validateRange(idx int, ipRange string) ([]error, maybeIPNet) {
	if v.isBlank(ipRange) {
		return []error{bosherr.Errorf("networks[%d].subnets[0].range must be provided", idx)}, &nothingIpNet{}
	} else {
		_, ipNet, err := net.ParseCIDR(ipRange)
		if err != nil {
			return []error{bosherr.Errorf("networks[%d].subnets[0].range must be an ip range", idx)}, &nothingIpNet{}
		}

		return []error{}, &somethingIpNet{ipNet: ipNet}
	}
}
开发者ID:vestel,项目名称:bosh-init,代码行数:12,代码来源:validator.go


示例11: Validate

func (v Validator) Validate(release birel.Release, cpiReleaseJobName string) error {
	job, ok := release.FindJobByName(cpiReleaseJobName)
	if !ok {
		return bosherr.Errorf("CPI release must contain specified job '%s'", cpiReleaseJobName)
	}

	_, ok = job.FindTemplateByValue(ReleaseBinaryName)
	if !ok {
		return bosherr.Errorf("Specified CPI release job '%s' must contain a template that renders to target '%s'", cpiReleaseJobName, ReleaseBinaryName)
	}

	return nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:13,代码来源:validator.go


示例12: TaskID

func (r *TaskResponse) TaskID() (string, error) {
	complexResponse, ok := r.Value.(map[string]interface{})
	if !ok {
		return "", bosherr.Errorf("Failed to convert agent response to map %#v\n%s", r.Value, debug.Stack())
	}

	agentTaskID, ok := complexResponse["agent_task_id"]
	if !ok {
		return "", bosherr.Errorf("Failed to parse task id from agent response %#v", r.Value)
	}

	return agentTaskID.(string), nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:13,代码来源:agent_response.go


示例13: Resolve

func (r *resolver) Resolve(jobName, releaseName string) (bireljob.Job, error) {
	release, found := r.releaseManager.Find(releaseName)
	if !found {
		return bireljob.Job{}, bosherr.Errorf("Finding release '%s'", releaseName)
	}

	releaseJob, found := release.FindJobByName(jobName)
	if !found {
		return bireljob.Job{}, bosherr.Errorf("Finding job '%s' in release '%s'", jobName, releaseName)
	}

	return releaseJob, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:13,代码来源:job_resolver.go


示例14: ResourcePool

func (d Manifest) ResourcePool(jobName string) (ResourcePool, error) {
	job, found := d.FindJobByName(jobName)
	if !found {
		return ResourcePool{}, bosherr.Errorf("Could not find job with name: %s", jobName)
	}

	for _, resourcePool := range d.ResourcePools {
		if resourcePool.Name == job.ResourcePool {
			return resourcePool, nil
		}
	}
	err := bosherr.Errorf("Could not find resource pool '%s' for job '%s'", job.ResourcePool, jobName)
	return ResourcePool{}, err
}
开发者ID:hanzhefeng,项目名称:bosh-init,代码行数:14,代码来源:manifest.go


示例15: CompilePackage

func (c *agentClient) CompilePackage(packageSource agentclient.BlobRef, compiledPackageDependencies []agentclient.BlobRef) (compiledPackageRef agentclient.BlobRef, err error) {
	dependencies := make(map[string]BlobRef, len(compiledPackageDependencies))
	for _, dependency := range compiledPackageDependencies {
		dependencies[dependency.Name] = BlobRef{
			Name:        dependency.Name,
			Version:     dependency.Version,
			SHA1:        dependency.SHA1,
			BlobstoreID: dependency.BlobstoreID,
		}
	}

	args := []interface{}{
		packageSource.BlobstoreID,
		packageSource.SHA1,
		packageSource.Name,
		packageSource.Version,
		dependencies,
	}

	responseValue, err := c.sendAsyncTaskMessage("compile_package", args)
	if err != nil {
		return agentclient.BlobRef{}, bosherr.WrapError(err, "Sending 'compile_package' to the agent")
	}

	result, ok := responseValue["result"].(map[string]interface{})
	if !ok {
		return agentclient.BlobRef{}, bosherr.Errorf("Unable to parse 'compile_package' response from the agent: %#v", responseValue)
	}

	sha1, ok := result["sha1"].(string)
	if !ok {
		return agentclient.BlobRef{}, bosherr.Errorf("Unable to parse 'compile_package' response from the agent: %#v", responseValue)
	}

	blobstoreID, ok := result["blobstore_id"].(string)
	if !ok {
		return agentclient.BlobRef{}, bosherr.Errorf("Unable to parse 'compile_package' response from the agent: %#v", responseValue)
	}

	compiledPackageRef = agentclient.BlobRef{
		Name:        packageSource.Name,
		Version:     packageSource.Version,
		SHA1:        sha1,
		BlobstoreID: blobstoreID,
	}

	return compiledPackageRef, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:48,代码来源:agent_client.go


示例16: Validate

func (b externalBlobstore) Validate() error {
	if !b.runner.CommandExists(b.executable()) {
		return bosherr.Errorf("executable %s not found in PATH", b.executable())
	}

	return b.writeConfigFile()
}
开发者ID:vestel,项目名称:bosh-init,代码行数:7,代码来源:external_blobstore.go


示例17: CreateVM

func (c cloud) CreateVM(
	agentID string,
	stemcellCID string,
	cloudProperties biproperty.Map,
	networksInterfaces map[string]biproperty.Map,
	env biproperty.Map,
) (string, error) {
	method := "create_vm"
	diskLocality := []interface{}{} // not used with bosh-init
	cmdOutput, err := c.cpiCmdRunner.Run(
		c.context,
		method,
		agentID,
		stemcellCID,
		cloudProperties,
		networksInterfaces,
		diskLocality,
		env,
	)
	if err != nil {
		return "", err
	}

	if cmdOutput.Error != nil {
		return "", NewCPIError(method, *cmdOutput.Error)
	}

	// for create_vm, the result is a string of the vm cid
	cidString, ok := cmdOutput.Result.(string)
	if !ok {
		return "", bosherr.Errorf("Unexpected external CPI command result: '%#v'", cmdOutput.Result)
	}
	return cidString, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:34,代码来源:cloud.go


示例18: Create

func (cl CommandList) Create(name string) (Cmd, error) {
	if cl[name] == nil {
		return nil, bosherr.Errorf("Command '%s' unknown. See 'bosh-init help'", name)
	}

	return cl[name]()
}
开发者ID:vestel,项目名称:bosh-init,代码行数:7,代码来源:factory.go


示例19: Get

func (p provider) Get(name string) (Platform, error) {
	plat, found := p.platforms[name]
	if !found {
		return nil, bosherror.Errorf("Platform %s could not be found", name)
	}
	return plat, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:7,代码来源:provider.go


示例20: CreateDisk

func (c cloud) CreateDisk(size int, cloudProperties biproperty.Map, vmCID string) (string, error) {
	c.logger.Debug(c.logTag,
		"Creating disk with size %d, cloudProperties %#v, instanceID %s",
		size,
		cloudProperties,
		vmCID,
	)
	method := "create_disk"
	cmdOutput, err := c.cpiCmdRunner.Run(
		c.context,
		method,
		size,
		cloudProperties,
		vmCID,
	)
	if err != nil {
		return "", err
	}

	if cmdOutput.Error != nil {
		return "", NewCPIError(method, *cmdOutput.Error)
	}

	cidString, ok := cmdOutput.Result.(string)
	if !ok {
		return "", bosherr.Errorf("Unexpected external CPI command result: '%#v'", cmdOutput.Result)
	}
	return cidString, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:29,代码来源:cloud.go



注:本文中的github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/errors.Errorf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.WrapError函数代码示例发布时间:2022-05-23
下一篇:
Golang errors.Error函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap