本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/errors.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetDefaultNetwork
func (r defaultNetworkResolver) GetDefaultNetwork() (boshsettings.Network, error) {
network := boshsettings.Network{}
routes, err := r.routesSearcher.SearchRoutes()
if err != nil {
return network, bosherr.WrapError(err, "Searching routes")
}
if len(routes) == 0 {
return network, bosherr.New("No routes found")
}
for _, route := range routes {
if !route.IsDefault() {
continue
}
ip, err := r.ipResolver.GetPrimaryIPv4(route.InterfaceName)
if err != nil {
return network, bosherr.WrapError(
err, "Getting primary IPv4 for interface '%s'", route.InterfaceName)
}
return boshsettings.Network{
IP: ip.IP.String(),
Netmask: gonet.IP(ip.Mask).String(),
Gateway: route.Gateway,
}, nil
}
return network, bosherr.New("Failed to find default route")
}
示例2: GetPrimaryIPv4
func (r ipResolver) GetPrimaryIPv4(interfaceName string) (*gonet.IPNet, error) {
addrs, err := r.ifaceToAddrsFunc(interfaceName)
if err != nil {
return nil, bosherr.WrapError(err, "Looking up addresses for interface '%s'", interfaceName)
}
if len(addrs) == 0 {
return nil, bosherr.New("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.New("Failed to find primary IPv4 address for interface '%s'", interfaceName)
}
示例3: validate
func (c Config) validate() error {
if c.AssetsDir == "" {
return bosherr.New("Must provide non-empty assets_dir")
}
if c.ReposDir == "" {
return bosherr.New("Must provide non-empty repos_dir")
}
err := c.EventLog.Validate()
if err != nil {
return bosherr.WrapError(err, "Validating event_log configuration")
}
if c.Blobstore.Type != bpprov.BlobstoreConfigTypeLocal {
return bosherr.New("Blobstore type must be local")
}
err = c.Blobstore.Validate()
if err != nil {
return bosherr.WrapError(err, "Validating blobstore configuration")
}
return nil
}
示例4: buildJobReaders
func (tc ConcreteTemplatesCompiler) buildJobReaders(job bpdep.Job) ([]jobReader, error) {
var readers []jobReader
for _, template := range job.Templates {
rec, found, err := tc.tplToJobRepo.FindByTemplate(template)
if err != nil {
return readers, bosherr.WrapError(err, "Finding dep-template -> release-job record %s", template.Name)
} else if !found {
return readers, bosherr.New("Expected to find dep-template -> release-job record %s", template.Name)
}
jobRec, found, err := tc.jobsRepo.FindByReleaseJob(rec)
if err != nil {
return readers, bosherr.WrapError(err, "Finding job source blob %s", template.Name)
} else if !found {
return readers, bosherr.New("Expected to find job source blob %s -- %s", template.Name, rec)
}
jobURL := fmt.Sprintf("blobstore:///%s?fingerprint=%s", jobRec.BlobID, jobRec.SHA1)
reader := jobReader{
rec: rec,
tarReader: tc.jobReaderFactory.NewReader(jobURL),
}
readers = append(readers, reader)
}
return readers, nil
}
示例5: validateJob
func (v SyntaxValidator) validateJob(job *Job) error {
if job.Name == "" {
return bosherr.New("Missing job name")
}
if job.Template != nil {
return bosherr.New("'template' is deprecated in favor of 'templates'")
}
err := v.validateUpdate(&job.Update)
if err != nil {
return bosherr.WrapError(err, "Update")
}
props, err := bputil.NewStringKeyed().ConvertMap(job.PropertiesRaw)
if err != nil {
return bosherr.WrapError(err, "Properties")
}
job.Properties = props
for i, na := range job.NetworkAssociations {
err := v.validateNetworkAssociation(&job.NetworkAssociations[i])
if err != nil {
return bosherr.WrapError(err, "Network association %s (%d)", na.NetworkName, i)
}
}
return nil
}
示例6: NewWatchTimeFromString
func NewWatchTimeFromString(str string) (WatchTime, error) {
var watchTime WatchTime
parts := strings.Split(str, "-")
if len(parts) != 2 {
return watchTime, bosherr.New("Invalid watch time range %s", str)
}
min, err := strconv.Atoi(strings.Trim(parts[0], " "))
if err != nil {
return watchTime, bosherr.WrapError(
err, "Non-positive number as watch time minimum %s", parts[0])
}
max, err := strconv.Atoi(strings.Trim(parts[1], " "))
if err != nil {
return watchTime, bosherr.WrapError(
err, "Non-positive number as watch time maximum %s", parts[1])
}
if max < min {
return watchTime, bosherr.New(
"Watch time must have maximum greater than or equal minimum %s", str)
}
watchTime[0], watchTime[1] = min, max
return watchTime, nil
}
示例7: Validate
func (v SyntaxValidator) Validate() error {
if v.release.Name == "" {
return bosherr.New("Missing release name")
}
if v.release.Version == "" {
return bosherr.New("Missing release version")
}
if v.release.CommitHash == "" {
return bosherr.New("Missing release commit_hash")
}
for i, job := range v.release.Jobs {
err := v.validateJob(&v.release.Jobs[i])
if err != nil {
return bosherr.WrapError(err, "Job %s (%d)", job.Name, i)
}
}
for i, pkg := range v.release.Packages {
err := v.validatePkg(&v.release.Packages[i])
if err != nil {
return bosherr.WrapError(err, "Package %s (%d)", pkg.Name, i)
}
}
return nil
}
示例8: validateNetworkAssociation
func (v SemanticValidator) validateNetworkAssociation(na NetworkAssociation) error {
if na.Network == nil {
return bosherr.New("Missing associated network")
}
if na.MustHaveStaticIP && na.StaticIP == nil {
return bosherr.New("Missing static IP assignment")
}
return nil
}
示例9: Get
func (bc FileBundleCollection) Get(definition BundleDefinition) (Bundle, error) {
if len(definition.BundleName()) == 0 {
return nil, bosherr.New("Missing bundle name")
}
if len(definition.BundleVersion()) == 0 {
return nil, bosherr.New("Missing bundle version")
}
installPath := filepath.Join(bc.installPath, bc.name, definition.BundleName(), definition.BundleVersion())
enablePath := filepath.Join(bc.enablePath, bc.name, definition.BundleName())
return NewFileBundle(installPath, enablePath, bc.fs, bc.logger), nil
}
示例10: validateNetworkType
func (v SyntaxValidator) validateNetworkType(networkType string) error {
if networkType == "" {
return bosherr.New("Missing network type")
}
for _, t := range NetworkTypes {
if networkType == t {
return nil
}
}
return bosherr.New("Unknown network type %s", networkType)
}
示例11: validateRelease
func (v SyntaxValidator) validateRelease(release *Release) error {
if release.Name == "" {
return bosherr.New("Missing release name")
}
if release.Version == "" {
return bosherr.New("Missing release version")
}
if release.URL == "" {
return bosherr.New("Missing release URL")
}
return nil
}
示例12: Find
func (ri DBIndex) Find(key interface{}, value interface{}) error {
rawKey, err := ri.structToMap(key)
if err != nil {
return err
}
rawKeyBytes, err := json.Marshal(rawKey)
if err != nil {
return err
}
rows, err := ri.adapter.Find(rawKeyBytes)
if err != nil {
return err
}
if rows == nil {
return bosherr.New("Expected to find entries for key '%s'", rawKeyBytes)
}
if !rows.Next() {
return bpindex.ErrNotFound
}
var rawEntryBytes []byte
err = rows.Scan(&rawEntryBytes)
if err != nil {
return err
}
if rows.Next() {
// todo should rows.Err() be called before returning
return bosherr.New("Expected to not find more than 1 entry for key '%s'", rawKeyBytes)
}
err = rows.Err()
if err != nil {
return err
}
err = json.Unmarshal(rawEntryBytes, &value)
if err != nil {
return err
}
return nil
}
示例13: stopRunsv
func (p RunitProvisioner) stopRunsv(name string, stopTimeout time.Duration) error {
p.logger.Info(runitProvisionerLogTag, "Stopping runsv")
// Potentially tried to deprovision before ever provisioning
if !p.runner.CommandExists("sv") {
return nil
}
downStdout, _, _, err := p.runner.RunCommand("sv", "down", name)
if err != nil {
p.logger.Error(runitProvisionerLogTag, "Ignoring down error %s", err)
}
// If runsv configuration does not exist, service was never started
if strings.Contains(downStdout, "file does not exist") {
return nil
}
var lastStatusStdout string
var passedDuration time.Duration
for ; passedDuration < stopTimeout; passedDuration += runitStopStepDuration {
lastStatusStdout, _, _, _ = p.runner.RunCommand("sv", "status", name)
if runitStatusDownRegex.MatchString(lastStatusStdout) {
return nil
}
time.Sleep(runitStopStepDuration)
}
return bosherr.New("Failed to stop runsv for %s. Output: %s", name, lastStatusStdout)
}
示例14: validateTemplate
func (v SemanticValidator) validateTemplate(template Template) error {
if template.Release == nil {
return bosherr.New("Missing associated release")
}
return nil
}
示例15: Run
func (a MountDiskAction) Run(diskCid string) (interface{}, error) {
err := a.settingsService.LoadSettings()
if err != nil {
return nil, bosherr.WrapError(err, "Refreshing the settings")
}
settings := a.settingsService.GetSettings()
devicePath, found := settings.Disks.Persistent[diskCid]
if !found {
return nil, bosherr.New("Persistent disk with volume id '%s' could not be found", diskCid)
}
mountPoint := a.dirProvider.StoreDir()
isMountPoint, err := a.mountPoints.IsMountPoint(mountPoint)
if err != nil {
return nil, bosherr.WrapError(err, "Checking mount point")
}
if isMountPoint {
mountPoint = a.dirProvider.StoreMigrationDir()
}
err = a.diskMounter.MountPersistentDisk(devicePath, mountPoint)
if err != nil {
return nil, bosherr.WrapError(err, "Mounting persistent disk")
}
return map[string]string{}, nil
}