本文整理匯總了Golang中bosh/errors.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: shouldMount
func (m linuxMounter) shouldMount(partitionPath, mountPoint string) (shouldMount bool, err error) {
isMounted, err := m.searchMounts(func(mountedPartitionPath, mountedMountPoint string) (found bool, err error) {
switch {
case mountedPartitionPath == partitionPath && mountedMountPoint == mountPoint:
found = true
return
case mountedPartitionPath == partitionPath && mountedMountPoint != mountPoint:
err = bosherr.New("Device %s is already mounted to %s, can't mount to %s",
mountedPartitionPath, mountedMountPoint, mountPoint)
return
case mountedMountPoint == mountPoint:
err = bosherr.New("Device %s is already mounted to %s, can't mount %s",
mountedPartitionPath, mountedMountPoint, partitionPath)
return
}
return
})
if err != nil {
err = bosherr.WrapError(err, "Searching mounts")
return
}
shouldMount = !isMounted
return
}
示例2: 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
}
示例3: 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")
}
示例4: 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
}
示例5: Run
func (r concreteRunner) Run(action Action, payloadBytes []byte) (value interface{}, err error) {
payloadArgs, err := r.extractJsonArguments(payloadBytes)
if err != nil {
err = bosherr.WrapError(err, "Extracting json arguments")
return
}
actionValue := reflect.ValueOf(action)
runMethodValue := actionValue.MethodByName("Run")
if runMethodValue.Kind() != reflect.Func {
err = bosherr.New("Run method not found")
return
}
runMethodType := runMethodValue.Type()
if r.invalidReturnTypes(runMethodType) {
err = bosherr.New("Run method should return a value and an error")
return
}
methodArgs, err := r.extractMethodArgs(runMethodType, payloadArgs)
if err != nil {
err = bosherr.WrapError(err, "Extracting method arguments from payload")
return
}
values := runMethodValue.Call(methodArgs)
return r.extractReturns(values)
}
示例6: 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)
}
示例7: 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
}
示例8: 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.NewTarReader(jobURL),
}
readers = append(readers, reader)
}
return readers, nil
}
示例9: Run
func (a DrainAction) Run(drainType DrainType, newSpecs ...boshas.V1ApplySpec) (int, error) {
currentSpec, err := a.specService.Get()
if err != nil {
return 0, bosherr.WrapError(err, "Getting current spec")
}
if len(currentSpec.JobSpec.Template) == 0 {
if drainType == DrainTypeStatus {
return 0, bosherr.New("Check Status on Drain action requires job spec")
} else {
return 0, nil
}
}
err = a.jobSupervisor.Unmonitor()
if err != nil {
return 0, bosherr.WrapError(err, "Unmonitoring services")
}
drainScript := a.drainScriptProvider.NewDrainScript(currentSpec.JobSpec.Template)
var params boshdrain.DrainScriptParams
switch drainType {
case DrainTypeUpdate:
if len(newSpecs) == 0 {
return 0, bosherr.New("Drain update requires new spec")
}
params = boshdrain.NewUpdateDrainParams(currentSpec, newSpecs[0])
case DrainTypeShutdown:
err = a.notifier.NotifyShutdown()
if err != nil {
return 0, bosherr.WrapError(err, "Notifying shutdown")
}
params = boshdrain.NewShutdownDrainParams()
case DrainTypeStatus:
params = boshdrain.NewStatusDrainParams()
}
if !drainScript.Exists() {
if drainType == DrainTypeStatus {
return 0, bosherr.New("Check Status on Drain action requires a valid drain script")
} else {
return 0, nil
}
}
value, err := drainScript.Run(params)
if err != nil {
return 0, bosherr.WrapError(err, "Running Drain Script")
}
return value, nil
}
示例10: checkBundle
func (s *FileBundleCollection) checkBundle(bundle Bundle) error {
if len(bundle.BundleName()) == 0 {
return bosherr.New("missing bundle name")
}
if len(bundle.BundleVersion()) == 0 {
return bosherr.New("missing bundle version")
}
return nil
}
示例11: checkBundle
func (s *FileBundleCollection) checkBundle(bundle Bundle) (err error) {
if len(bundle.BundleName()) == 0 {
err = bosherr.New("missing bundle name")
return
}
if len(bundle.BundleVersion()) == 0 {
err = bosherr.New("missing bundle version")
return
}
return
}
示例12: 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
}
示例13: 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)
}
示例14: Validate
func (blobstore local) Validate() error {
path, found := blobstore.options["blobstore_path"]
if !found {
return bosherr.New("missing blobstore_path")
}
_, ok := path.(string)
if !ok {
return bosherr.New("blobstore_path must be a string")
}
return nil
}
示例15: 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
}