本文整理汇总了Golang中github.com/joeshaw/multierror.Errors类的典型用法代码示例。如果您正苦于以下问题:Golang Errors类的具体用法?Golang Errors怎么用?Golang Errors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Errors类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: New
// New creates new instance of MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
// Additional configuration options
config := struct {
ServerStatusPath string `config:"server_status_path"`
Username string `config:"username"`
Password string `config:"password"`
}{
ServerStatusPath: defaultPath,
Username: "",
Password: "",
}
if err := base.Module().UnpackConfig(&config); err != nil {
return nil, err
}
metricSet := &MetricSet{
BaseMetricSet: base,
URLs: make(map[string]string, len(base.Module().Config().Hosts)),
}
// Parse the config, create URLs, and check for errors.
var errs multierror.Errors
for _, host := range base.Module().Config().Hosts {
u, err := getURL(config.Username, config.Password, config.ServerStatusPath, host)
if err != nil {
errs = append(errs, err)
continue
}
metricSet.URLs[host] = u.String()
debugf("apache-status URL=%s", redactPassword(*u))
}
return metricSet, errs.Err()
}
开发者ID:yan2jared,项目名称:beats,代码行数:36,代码来源:status.go
示例2: Validate
// Validate validates the Settings data and returns an error describing
// all problems or nil if there are none.
func (s Settings) Validate() error {
// TODO: winlogbeat should not try to validate top-level beats config
validKeys := []string{
"fields", "fields_under_root", "tags",
"name", "refresh_topology_freq", "ignore_outgoing", "topology_expire", "geoip",
"queue_size", "bulk_queue_size", "max_procs",
"processors", "logging", "output", "path", "winlogbeat",
}
sort.Strings(validKeys)
// Check for invalid top-level keys.
var errs multierror.Errors
for k := range s.Raw {
k = strings.ToLower(k)
i := sort.SearchStrings(validKeys, k)
if i >= len(validKeys) || validKeys[i] != k {
errs = append(errs, fmt.Errorf("Invalid top-level key '%s' "+
"found. Valid keys are %s", k, strings.Join(validKeys, ", ")))
}
}
err := s.Winlogbeat.Validate()
if err != nil {
errs = append(errs, err)
}
return errs.Err()
}
开发者ID:ChongFeng,项目名称:beats,代码行数:31,代码来源:config.go
示例3: uninstallLog
// uninstallLog unregisters the event logger from the registry and closes the
// log's handle if it is open.
func uninstallLog(provider, source string, log *elog.Log) error {
var errs multierror.Errors
if log != nil {
err := clearEventLog(Handle(log.Handle), "")
if err != nil {
errs = append(errs, err)
}
err = log.Close()
if err != nil {
errs = append(errs, err)
}
}
err := elog.RemoveSource(providerName, sourceName)
if err != nil {
errs = append(errs, err)
}
err = elog.RemoveProvider(providerName)
if err != nil {
errs = append(errs, err)
}
return errs.Err()
}
开发者ID:tsg,项目名称:beats,代码行数:29,代码来源:eventlog_integration_test.go
示例4: initLog
// initLog initializes an event logger. It registers the source name with
// the registry if it does not already exist.
func initLog(provider, source, msgFile string) (*elog.Log, error) {
// Install entry to registry:
_, err := elog.Install(providerName, sourceName, msgFile, true, allLevels)
if err != nil {
return nil, err
}
// Open a new logger for writing events:
log, err := elog.Open(sourceName)
if err != nil {
var errs multierror.Errors
errs = append(errs, err)
err := elog.RemoveSource(providerName, sourceName)
if err != nil {
errs = append(errs, err)
}
err = elog.RemoveProvider(providerName)
if err != nil {
errs = append(errs, err)
}
return nil, errs.Err()
}
return log, nil
}
开发者ID:tsg,项目名称:beats,代码行数:27,代码来源:eventlog_integration_test.go
示例5: Setup
// Setup the URLs to the mod_status endpoints.
func (m *MetricSeter) Setup(ms *helper.MetricSet) error {
// Additional configuration options
config := struct {
ServerStatusPath string `config:"server_status_path"`
Username string `config:"username"`
Password string `config:"password"`
}{
ServerStatusPath: defaultPath,
Username: "",
Password: "",
}
if err := ms.Module.ProcessConfig(&config); err != nil {
return err
}
m.URLs = make(map[string]string, len(ms.Config.Hosts))
// Parse the config, create URLs, and check for errors.
var errs multierror.Errors
for _, host := range ms.Config.Hosts {
u, err := getURL(config.Username, config.Password, config.ServerStatusPath, host)
if err != nil {
errs = append(errs, err)
continue
}
m.URLs[host] = u.String()
debugf("apache-status URL=%s", redactPassword(*u))
}
return errs.Err()
}
开发者ID:radoondas,项目名称:apachebeat,代码行数:33,代码来源:status.go
示例6: Validate
// Validate validates the winEventLogConfig data and returns an error describing
// any problems or nil.
func (c *winEventLogConfig) Validate() error {
var errs multierror.Errors
if c.Name == "" {
errs = append(errs, fmt.Errorf("event log is missing a 'name'"))
}
return errs.Err()
}
开发者ID:andrewkroh,项目名称:beats,代码行数:10,代码来源:wineventlog.go
示例7: UpdateAll
// UpdateAll remote repositories
func UpdateAll() error {
var Errors multierror.Errors
for _, repository := range *allRepositories {
err := Update(repository.Name)
if err != nil {
Errors = append(Errors, err)
}
}
return Errors.Err()
}
开发者ID:ashwanthkumar,项目名称:marathonctl,代码行数:11,代码来源:main.go
示例8: newModuleWrappers
// newModuleWrappers creates new Modules and their associated MetricSets based
// on the given configuration. It constructs the supporting filters and
// publisher client and stores it all in a moduleWrapper.
func newModuleWrappers(
modulesConfig []*common.Config,
r *mb.Register,
publisher *publisher.Publisher,
) ([]*moduleWrapper, error) {
modules, err := mb.NewModules(modulesConfig, r)
if err != nil {
return nil, err
}
// Wrap the Modules and MetricSet's.
var wrappers []*moduleWrapper
var errs multierror.Errors
for k, v := range modules {
debugf("initializing Module type %s, %T=%+v", k.Name(), k, k)
f, err := filter.New(k.Config().Filters)
if err != nil {
errs = append(errs, errors.Wrapf(err, "module %s", k.Name()))
continue
}
mw := &moduleWrapper{
Module: k,
filters: f,
pubClient: publisher.Connect(),
}
wrappers = append(wrappers, mw)
msws := make([]*metricSetWrapper, 0, len(v))
for _, ms := range v {
debugf("initializing MetricSet type %s/%s, %T=%+v",
ms.Module().Name(), ms.Name(), ms, ms)
msw := &metricSetWrapper{
MetricSet: ms,
module: mw,
stats: new(expvar.Map).Init(),
}
msws = append(msws, msw)
// Initialize expvar stats for this MetricSet.
fetches.Set(fmt.Sprintf("%s-%s", mw.Name(), msw.Name()), msw.stats)
msw.stats.Add(successesKey, 0)
msw.stats.Add(failuresKey, 0)
msw.stats.Add(eventsKey, 0)
}
mw.metricSets = msws
}
return wrappers, errs.Err()
}
开发者ID:yan2jared,项目名称:beats,代码行数:53,代码来源:module.go
示例9: LoadTLSConfig
// LoadTLSConfig will load a certificate from config with all TLS based keys
// defined. If Certificate and CertificateKey are configured, client authentication
// will be configured. If no CAs are configured, the host CA will be used by go
// built-in TLS support.
func LoadTLSConfig(config *TLSConfig) (*transport.TLSConfig, error) {
if !config.IsEnabled() {
return nil, nil
}
fail := multierror.Errors{}
logFail := func(es ...error) {
for _, e := range es {
if e != nil {
fail = append(fail, e)
}
}
}
var cipherSuites []uint16
for _, suite := range config.CipherSuites {
cipherSuites = append(cipherSuites, uint16(suite))
}
var curves []tls.CurveID
for _, id := range config.CurveTypes {
curves = append(curves, tls.CurveID(id))
}
cert, err := loadCertificate(&config.Certificate)
logFail(err)
cas, errs := loadCertificateAuthorities(config.CAs)
logFail(errs...)
// fail, if any error occurred when loading certificate files
if err = fail.Err(); err != nil {
return nil, err
}
var certs []tls.Certificate
if cert != nil {
certs = []tls.Certificate{*cert}
}
// return config if no error occurred
return &transport.TLSConfig{
Versions: config.Versions,
Verification: config.VerificationMode,
Certificates: certs,
RootCAs: cas,
CipherSuites: cipherSuites,
CurvePreferences: curves,
}, nil
}
开发者ID:ruflin,项目名称:beats,代码行数:54,代码来源:tls.go
示例10: newBaseModulesFromConfig
// newBaseModulesFromConfig creates new BaseModules from a list of configs
// each containing ModuleConfig data.
func newBaseModulesFromConfig(config []*common.Config) ([]BaseModule, error) {
var errs multierror.Errors
baseModules := make([]BaseModule, 0, len(config))
for _, rawConfig := range config {
bm, err := newBaseModuleFromConfig(rawConfig)
if err != nil {
errs = append(errs, err)
continue
}
if bm.config.Enabled {
baseModules = append(baseModules, bm)
}
}
return baseModules, errs.Err()
}
开发者ID:andrewkroh,项目名称:beats,代码行数:19,代码来源:builders.go
示例11: NewModuleWrappers
// NewModuleWrappers creates new Modules and their associated MetricSets based
// on the given configuration. It constructs the supporting filters and stores
// them all in a ModuleWrapper.
func NewModuleWrappers(modulesConfig []*common.Config, r *mb.Register) ([]*ModuleWrapper, error) {
modules, err := mb.NewModules(modulesConfig, r)
if err != nil {
return nil, err
}
// Wrap the Modules and MetricSet's.
var wrappers []*ModuleWrapper
var errs multierror.Errors
for k, v := range modules {
debugf("Initializing Module type '%s': %T=%+v", k.Name(), k, k)
f, err := filter.New(k.Config().Filters)
if err != nil {
errs = append(errs, errors.Wrapf(err, "module %s", k.Name()))
continue
}
mw := &ModuleWrapper{
Module: k,
filters: f,
}
wrappers = append(wrappers, mw)
msws := make([]*metricSetWrapper, 0, len(v))
for _, ms := range v {
debugf("Initializing MetricSet type '%s/%s' for host '%s': %T=%+v",
ms.Module().Name(), ms.Name(), ms.Host(), ms, ms)
expMap, err := getMetricSetExpvarMap(mw.Name(), ms.Name())
if err != nil {
return nil, err
}
msw := &metricSetWrapper{
MetricSet: ms,
module: mw,
stats: expMap,
}
msws = append(msws, msw)
}
mw.metricSets = msws
}
return wrappers, errs.Err()
}
开发者ID:mrkschan,项目名称:beats,代码行数:48,代码来源:module.go
示例12: Validate
// Validate validates the eventLoggingConfig data and returns an error
// describing any problems or nil.
func (c *eventLoggingConfig) Validate() error {
var errs multierror.Errors
if c.Name == "" {
errs = append(errs, fmt.Errorf("event log is missing a 'name'"))
}
if c.ReadBufferSize > win.MaxEventBufferSize {
errs = append(errs, fmt.Errorf("'read_buffer_size' must be less than "+
"%d bytes", win.MaxEventBufferSize))
}
if c.FormatBufferSize > win.MaxFormatMessageBufferSize {
errs = append(errs, fmt.Errorf("'format_buffer_size' must be less than "+
"%d bytes", win.MaxFormatMessageBufferSize))
}
return errs.Err()
}
开发者ID:urso,项目名称:beats,代码行数:20,代码来源:eventlogging.go
示例13: Process
func Process(spec interface{}) error {
var el multierror.Errors
e := func(err error) {
if err != nil {
el = append(el, err)
}
}
if conf.Settings.UseDB {
e(db.Process(spec))
}
if conf.Settings.UseFile {
e(file.Process(spec))
}
if conf.Settings.UseEnv {
e(env.Process(conf.Settings.AppName, spec))
}
return el.Err()
}
开发者ID:ryansb,项目名称:gofigure,代码行数:18,代码来源:process.go
示例14: Process
// Process takes a spec and a list of files. The list of files is in
// **reverse** order of precedence, meaning that a value in the first file can
// be overridden by any subsequent file.
//
// Example:
// Process(mySpec, "/etc/myapp.json", "/usr/local/etc/myapp.json", "/home/me/.myapp.json")
// values in /home/me/.myapp.json will override any values set in /etc/myapp.json
func Process(spec interface{}) error {
var el multierror.Errors
res := map[string]interface{}{}
for _, fname := range conf.Settings.FileLocations {
contents, err := ioutil.ReadFile(fname)
if err != nil {
el = append(el, err)
continue
}
json.Unmarshal(contents, &res)
}
if err := merger.MapAndStruct(res, spec); err != nil {
el = append(el, err)
}
return el.Err()
}
开发者ID:ryansb,项目名称:gofigure,代码行数:25,代码来源:reader.go
示例15: KillAllContainers
func (d *DockerDaemon) KillAllContainers() error {
containers, err := d.Client.ListContainers(dockerapi.ListContainersOptions{})
if err != nil {
return err
}
var errs multierror.Errors
for _, container := range containers {
err = d.Client.KillContainer(dockerapi.KillContainerOptions{
ID: container.ID,
})
if err != nil {
errs = append(errs, err)
}
}
return errs.Err()
}
开发者ID:raceli,项目名称:resolvable,代码行数:19,代码来源:daemon.go
示例16: Validate
// Validate validates the Settings data and returns an error describing
// all problems or nil if there are none.
func (s Settings) Validate() error {
validKeys := []string{"filters", "logging", "output", "shipper", "winlogbeat"}
sort.Strings(validKeys)
// Check for invalid top-level keys.
var errs multierror.Errors
for k := range s.Raw {
k = strings.ToLower(k)
i := sort.SearchStrings(validKeys, k)
if i >= len(validKeys) || validKeys[i] != k {
errs = append(errs, fmt.Errorf("Invalid top-level key '%s' "+
"found. Valid keys are %s", k, strings.Join(validKeys, ", ")))
}
}
err := s.Winlogbeat.Validate()
if err != nil {
errs = append(errs, err)
}
return errs.Err()
}
开发者ID:radoondas,项目名称:apachebeat,代码行数:24,代码来源:config.go
示例17: createModules
func createModules(r *Register, baseModules []BaseModule) ([]Module, error) {
modules := make([]Module, 0, len(baseModules))
var errs multierror.Errors
for _, bm := range baseModules {
f := r.moduleFactory(bm.Name())
if f == nil {
f = DefaultModuleFactory
}
module, err := f(bm)
if err != nil {
errs = append(errs, err)
continue
}
modules = append(modules, module)
}
err := errs.Err()
if err != nil {
return nil, err
}
return modules, nil
}
开发者ID:andrewkroh,项目名称:beats,代码行数:23,代码来源:builders.go
示例18: Build
// Build builds a query from the given parameters. The query is returned as a
// XML string and can be used with Subscribe function.
func (q Query) Build() (string, error) {
var errs multierror.Errors
if q.Log == "" {
errs = append(errs, fmt.Errorf("empty log name"))
}
qp := &queryParams{Path: q.Log}
builders := []func(Query) error{
qp.ignoreOlderSelect,
qp.eventIDSelect,
qp.levelSelect,
qp.providerSelect,
}
for _, build := range builders {
if err := build(q); err != nil {
errs = append(errs, err)
}
}
if len(errs) > 0 {
return "", errs.Err()
}
return executeTemplate(queryTemplate, qp)
}
开发者ID:ChongFeng,项目名称:beats,代码行数:25,代码来源:query.go
示例19: initMetricSets
func initMetricSets(r *Register, modules []Module) (map[Module][]MetricSet, error) {
active := map[Module][]MetricSet{}
var errs multierror.Errors
for _, bms := range newBaseMetricSets(modules) {
f, err := r.metricSetFactory(bms.Module().Name(), bms.Name())
if err != nil {
errs = append(errs, err)
continue
}
metricSet, err := f(bms)
if err != nil {
errs = append(errs, err)
continue
}
err = mustImplementFetcher(metricSet)
if err != nil {
errs = append(errs, err)
continue
}
err = mustHaveModule(metricSet, bms)
if err != nil {
errs = append(errs, err)
continue
}
module := metricSet.Module()
active[module] = append(active[module], metricSet)
}
err := errs.Err()
if err != nil {
return nil, err
}
return active, nil
}
开发者ID:andrewkroh,项目名称:beats,代码行数:37,代码来源:builders.go
示例20: readConfig
func readConfig(
data map[string]interface{},
config interface{},
validKeys []string,
) error {
c, err := common.NewConfigFrom(data)
if err != nil {
return fmt.Errorf("Failed reading config. %v", err)
}
if err := c.Unpack(config); err != nil {
return fmt.Errorf("Failed unpacking config. %v", err)
}
var errs multierror.Errors
if len(validKeys) > 0 {
sort.Strings(validKeys)
// Check for invalid keys.
for k := range data {
k = strings.ToLower(k)
i := sort.SearchStrings(validKeys, k)
if i >= len(validKeys) || validKeys[i] != k {
errs = append(errs, fmt.Errorf("Invalid event log key '%s' "+
"found. Valid keys are %s", k, strings.Join(validKeys, ", ")))
}
}
}
if v, ok := config.(validator); ok {
if err := v.Validate(); err != nil {
errs = append(errs, err)
}
}
return errs.Err()
}
开发者ID:ChongFeng,项目名称:beats,代码行数:37,代码来源:factory.go
注:本文中的github.com/joeshaw/multierror.Errors类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论