當前位置: 首頁>>代碼示例>>Golang>>正文


Golang go-multierror.Append函數代碼示例

本文整理匯總了Golang中github.com/hashicorp/go-multierror.Append函數的典型用法代碼示例。如果您正苦於以下問題:Golang Append函數的具體用法?Golang Append怎麽用?Golang Append使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Append函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Finalize

// Finalize releases all i2c devices and exported digital and pwm pins.
func (e *Adaptor) Finalize() (err error) {
	for _, pin := range e.digitalPins {
		if pin != nil {
			if errs := pin.Unexport(); errs != nil {
				err = multierror.Append(err, errs)
			}
		}
	}
	for _, pin := range e.pwmPins {
		if pin != nil {
			if errs := pin.enable("0"); errs != nil {
				err = multierror.Append(err, errs)
			}
			if errs := pin.unexport(); errs != nil {
				err = multierror.Append(err, errs)
			}
		}
	}
	if e.i2cDevice != nil {
		if errs := e.i2cDevice.Close(); errs != nil {
			err = multierror.Append(err, errs)
		}
	}
	return
}
開發者ID:hybridgroup,項目名稱:gobot,代碼行數:26,代碼來源:joule_adaptor.go

示例2: FixPerms

func FixPerms() error {
	const read = 0444

	var merr error

	for _, file := range LogFiles {
		fi, err := os.Stat(file)
		if err != nil {
			if !os.IsNotExist(err) {
				merr = multierror.Append(merr, err)
			}

			continue
		}

		if (fi.Mode() & read) != read {
			err = os.Chmod(fi.Name(), fi.Mode()|read)
			if err != nil {
				merr = multierror.Append(merr, err)
			}
		}
	}

	return merr
}
開發者ID:koding,項目名稱:koding,代碼行數:25,代碼來源:output.go

示例3: call

func (c *callbacks) call(ident string) (err error) {
	c.mu.Lock()
	fns, ok := c.m[ident]
	delete(c.m, ident)
	c.mu.Unlock()

	if !ok {
		return nil
	}

	for i := range fns {
		// Start executing from callbacks from the newest to the oldest (like defer).
		fn := fns[len(fns)-i-1]

		// Ensure panic in a callback does not break executing other callbacks.
		func(fn func() error) {
			defer func() {
				if v := recover(); v != nil {
					e, ok := v.(error)
					if !ok {
						e = fmt.Errorf("%v", v)
					}
					err = multierror.Append(err, e)
				}
			}()

			if e := fn(); e != nil {
				err = multierror.Append(err, e)
			}
		}(fn)
	}

	return err
}
開發者ID:koding,項目名稱:koding,代碼行數:34,代碼來源:tunnelproxy.go

示例4: Connect

// Connect initializes the Edison for use with the Arduino beakout board
func (e *Adaptor) Connect() (err error) {
	e.digitalPins = make(map[int]sysfs.DigitalPin)
	e.pwmPins = make(map[int]*pwmPin)

	switch e.Board() {
	case "sparkfun":
		e.pinmap = sparkfunPinMap
		if errs := e.sparkfunSetup(); errs != nil {
			err = multierror.Append(err, errs)
		}
	case "arduino":
		e.pinmap = arduinoPinMap
		if errs := e.arduinoSetup(); errs != nil {
			err = multierror.Append(err, errs)
		}
	case "miniboard":
		e.pinmap = miniboardPinMap
		if errs := e.miniboardSetup(); errs != nil {
			err = multierror.Append(err, errs)
		}
	default:
		errs := errors.New("Unknown board type: " + e.Board())
		err = multierror.Append(err, errs)
	}
	return
}
開發者ID:hybridgroup,項目名稱:gobot,代碼行數:27,代碼來源:edison_adaptor.go

示例5: parseRawBool

func parseRawBool(key string, hcltree *hclObj.Object, errors *multierror.Error) bool {
	if rawValue := hcltree.Get(key, false); rawValue != nil {
		if rawValue.Type != hclObj.ValueTypeBool {
			errors = multierror.Append(errors, fmt.Errorf("Invalid type assigned to property: %s. Expected string type, Found %s", key, rawValue.Type))
		} else {
			return rawValue.Value.(bool)
		}
	} else {
		errors = multierror.Append(errors, fmt.Errorf("Property: %s not specified in the configuration", key))
	}
	return false
}
開發者ID:kapalhq,項目名稱:envoy,代碼行數:12,代碼來源:hcl_parser.go

示例6: Stop

// Stop stops a Robot's connections and Devices
func (r *Robot) Stop() error {
	var result error
	log.Println("Stopping Robot", r.Name, "...")
	err := r.Devices().Halt()
	if err != nil {
		result = multierror.Append(result, err)
	}
	err = r.Connections().Finalize()
	if err != nil {
		result = multierror.Append(result, err)
	}

	r.done <- true
	return result
}
開發者ID:hybridgroup,項目名稱:gobot,代碼行數:16,代碼來源:robot.go

示例7: Finalize

// Finalize closes connection to board and pins
func (c *Adaptor) Finalize() (err error) {
	for _, pin := range c.digitalPins {
		if pin != nil {
			if e := pin.Unexport(); e != nil {
				err = multierror.Append(err, e)
			}
		}
	}
	if c.i2cDevice != nil {
		if e := c.i2cDevice.Close(); e != nil {
			err = multierror.Append(err, e)
		}
	}
	return
}
開發者ID:hybridgroup,項目名稱:gobot,代碼行數:16,代碼來源:chip_adaptor.go

示例8: TestMasterFinalizeErrors

func TestMasterFinalizeErrors(t *testing.T) {
	g := initTestMaster1Robot()
	e := errors.New("adaptor finalize error 2")

	testAdaptorFinalize = func() (err error) {
		return e
	}

	var expected error
	expected = multierror.Append(expected, e)
	expected = multierror.Append(expected, e)
	expected = multierror.Append(expected, e)

	gobottest.Assert(t, g.Start(), nil)
	gobottest.Assert(t, g.Stop(), expected)
}
開發者ID:hybridgroup,項目名稱:gobot,代碼行數:16,代碼來源:master_test.go

示例9: parseMaxExecutions

func parseMaxExecutions(jobNode *hclObj.Object, errors *multierror.Error) string {
	if rawCron := jobNode.Get("max_executions", false); rawCron != nil {
		if rawCron.Len() > 1 {
			errors = multierror.Append(errors, fmt.Errorf("max_executions was specified more than once"))
		} else {
			if rawCron.Type != hclObj.ValueTypeString {
				errors = multierror.Append(errors, fmt.Errorf("max_executions was specified as an invalid type - expected string, found %s", rawCron.Type))
			} else {
				return rawCron.Value.(string)
			}
		}
	} else {
		errors = multierror.Append(errors, fmt.Errorf("No max_executions was specified in the configuration"))
	}
	return ""
}
開發者ID:kapalhq,項目名稱:mozo,代碼行數:16,代碼來源:parser.go

示例10: parseJob

func parseJob(jobNode *hclObj.Object, errors *multierror.Error) JobConfig {
	config := JobConfig{}

	if jobNode.Len() > 1 {
		errors = multierror.Append(errors, fmt.Errorf("job was specified more than once"))
	} else {
		if jobNode.Type != hclObj.ValueTypeObject {
			errors = multierror.Append(errors, fmt.Errorf("job was specified as an invalid type - expected object, found %s", jobNode.Type))
		} else {
			config.Name = jobNode.Key
			config.Trigger = parseJobTrigger(jobNode, errors)
			config.Exec = parseExec(jobNode, errors)
		}
	}
	return config
}
開發者ID:kapalhq,項目名稱:mozo,代碼行數:16,代碼來源:parser.go

示例11: Exit

// Exit causes as much of the Remotes struct to shutdown as quickly and as
// cleanly as possible. It only returns once everything is shutdown.
func (obj *Remotes) Exit() error {
	obj.lock.Lock()
	obj.exiting = true // don't spawn new ones once this flag is set!
	obj.lock.Unlock()
	close(obj.exitChan)
	var reterr error
	for _, f := range obj.remotes {
		sshobj, exists := obj.sshmap[f]
		if !exists || sshobj == nil {
			continue
		}

		// TODO: should we run these as go routines?
		if err := sshobj.Stop(); err != nil {
			err = errwrap.Wrapf(err, "Remote: Error stopping!")
			reterr = multierr.Append(reterr, err) // list of errors
		}
	}

	if obj.callbackCancelFunc != nil {
		obj.callbackCancelFunc() // cancel our callback
	}

	defer obj.cuid.Unregister()
	obj.wg.Wait() // wait for everyone to exit
	return reterr
}
開發者ID:purpleidea,項目名稱:mgmt,代碼行數:29,代碼來源:remote.go

示例12: Validate

func (auth *GitHubAuthFlag) Validate() error {
	var errs *multierror.Error
	if auth.ClientID == "" || auth.ClientSecret == "" {
		errs = multierror.Append(
			errs,
			errors.New("must specify --github-auth-client-id and --github-auth-client-secret to use GitHub OAuth."),
		)
	}
	if len(auth.Organizations) == 0 && len(auth.Teams) == 0 && len(auth.Users) == 0 {
		errs = multierror.Append(
			errs,
			errors.New("at least one of the following is required for github-auth: organizations, teams, users."),
		)
	}
	return errs.ErrorOrNil()
}
開發者ID:alphagov,項目名稱:paas-cf,代碼行數:16,代碼來源:auth_flags.go

示例13: OpenPubKey

func OpenPubKey(location string) (types.ACIdentifier, *os.File, error) {
	if app := tryAppFromString(location); app != nil {
		// Proper ACIdentifier given, let's do the discovery
		// TODO: hostHeaders, insecure
		if pks, _, err := discovery.DiscoverPublicKeys(*app, nil, 0); err != nil {
			return app.Name, nil, err
		} else {
			// We assume multiple returned keys are alternatives, not
			// multiple different valid keychains.
			var err error
			for _, keyurl := range pks {
				if keyf, er1 := OpenLocation(keyurl); er1 != nil {
					err = multierror.Append(err, er1)
				} else {
					return app.Name, keyf, nil
				}
			}
			// All keys erred
			return app.Name, nil, err
		}
	} else {
		// Not an ACIdentifier, let's open as raw location
		f, err := OpenLocation(location)
		return "", f, err
	}
}
開發者ID:saper,項目名稱:jetpack,代碼行數:26,代碼來源:discovery.go

示例14: parseVersion

func parseVersion(hcltree *hclObj.Object, errors *multierror.Error) string {
	if rawVersion := hcltree.Get("version", false); rawVersion != nil {
		if rawVersion.Len() > 1 {
			errors = multierror.Append(errors, fmt.Errorf("Version was specified more than once"))
		} else {
			if rawVersion.Type != hclObj.ValueTypeString {
				errors = multierror.Append(errors, fmt.Errorf("Version was specified as an invalid type - expected string, found %s", rawVersion.Type))
			} else {
				return rawVersion.Value.(string)
			}
		}
	} else {
		errors = multierror.Append(errors, fmt.Errorf("No version was specified in the configuration"))
	}
	return "*** Error"
}
開發者ID:kapalhq,項目名稱:mozo,代碼行數:16,代碼來源:parser.go

示例15: deleteSecurityGroupRules

func deleteSecurityGroupRules(d *schema.ResourceData, meta interface{}, rules *schema.Set, ors *schema.Set) error {
	var errs *multierror.Error

	var wg sync.WaitGroup
	wg.Add(ors.Len())

	sem := make(chan struct{}, d.Get("parallelism").(int))
	for _, rule := range ors.List() {
		// Put a sleep here to avoid DoS'ing the API
		time.Sleep(500 * time.Millisecond)

		go func(rule map[string]interface{}) {
			defer wg.Done()
			sem <- struct{}{}

			// Create a single rule
			err := deleteSecurityGroupRule(d, meta, rule)
			if err != nil {
				errs = multierror.Append(errs, err)
			}

			// If we have at least one UUID, we need to save the rule
			if len(rule["uuids"].(map[string]interface{})) > 0 {
				rules.Add(rule)
			}

			<-sem
		}(rule.(map[string]interface{}))
	}

	wg.Wait()

	return errs.ErrorOrNil()
}
開發者ID:paultyng,項目名稱:terraform,代碼行數:34,代碼來源:resource_cloudstack_security_group_rule.go


注:本文中的github.com/hashicorp/go-multierror.Append函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。