当前位置: 首页>>代码示例>>Golang>>正文


Golang errgo.Newf函数代码示例

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


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

示例1: NewFioRunner

func NewFioRunner(c FioConfiguration) (FioRunner, error) {
	var err error

	if !fioExists() {
		return FioRunner{}, errgo.Newf("Cannot locate fio. Looks like it is not installed on your system.")
	}

	if c.GenerateBandwithLogs || c.GenerateIOPSLogs || c.GenerateLatencyLogs {
		if len(c.LogsPrefix) < 1 {
			return FioRunner{}, errgo.Newf("You have to set a log file prefix")

		}
	}

	if c.JobDirectory, err = filepath.Abs(c.JobDirectory); err != nil {
		return FioRunner{}, errgo.Mask(err)
	}

	if c.WorkingDirectory, err = filepath.Abs(c.WorkingDirectory); err != nil {
		return FioRunner{}, errgo.Mask(err)
	}

	if c.LogsDirectory, err = filepath.Abs(c.LogsDirectory); err != nil {
		return FioRunner{}, errgo.Mask(err)
	}

	return FioRunner{
		conf: c,
	}, nil
}
开发者ID:giantswarm,项目名称:io-benchmarks,代码行数:30,代码来源:fio.go

示例2: parseDockerPort

func parseDockerPort(input string, dp *Port) error {
	s := strings.Split(input, "/")

	switch len(s) {
	case 1:
		dp.Port = s[0]
		dp.Protocol = protocolTCP
	case 2:
		dp.Port = s[0]
		dp.Protocol = s[1]
	default:
		return errgo.Newf("Invalid format, must be either <port> or <port>/<prot>, got '%s'", input)
	}

	if parsedPort, err := strconv.Atoi(dp.Port); err != nil {
		return errgo.Notef(err, "Port must be a number, got '%s'", dp.Port)
	} else if parsedPort < 1 || parsedPort > 65535 {
		return errgo.Notef(err, "Port must be a number between 1 and 65535, got '%s'", dp.Port)
	}

	switch dp.Protocol {
	case "":
		return errgo.Newf("Protocol must not be empty.")
	case protocolUDP, protocolTCP:
		return nil
	default:
		return errgo.Newf("Unknown protocol: '%s' in '%s'", dp.Protocol, input)
	}
}
开发者ID:pulcy,项目名称:j2,代码行数:29,代码来源:port.go

示例3: createWorkingDirectory

func (r FioRunner) createWorkingDirectory() error {
	f, err := os.Open(r.conf.WorkingDirectory)

	if err != nil {
		if os.IsNotExist(err) {
			os.Mkdir(r.conf.WorkingDirectory, 0755)
			return nil
		} else {
			return errgo.Mask(err)
		}
	}

	if fi, err := f.Stat(); err != nil {
		return errgo.Mask(err)
	} else if !fi.IsDir() {
		return errgo.Newf("Working directory '%s' exists but appears to be a file.", r.conf.WorkingDirectory)
	}

	if fis, err := f.Readdir(0); err != nil {
		return errgo.Mask(err)
	} else if len(fis) > 0 {
		return errgo.Newf("Working directory '%s' appears to be not empty.", r.conf.WorkingDirectory)
	}

	return nil
}
开发者ID:giantswarm,项目名称:io-benchmarks,代码行数:26,代码来源:fio.go

示例4: runKillInstance

func runKillInstance(args []string) (exit int) {
	if len(args) != 2 {
		return exitError("wrong number of arguments. Usage: kocho kill-instance <swarm> <instance>")
	}
	swarmName := args[0]
	instanceID := args[1]

	s, err := swarmService.Get(swarmName, swarm.AWS)
	if err != nil {
		return exitError(fmt.Sprintf("couldn't get instances of swarm: %s", swarmName), err)
	}

	instances, err := s.GetInstances()
	if err != nil {
		return exitError(err)
	}

	killableInstance, err := swarmtypes.FindInstanceById(instances, instanceID)
	if err != nil {
		return exitError(errgo.WithCausef(err, nil, "failed to find provided instance: %s", instanceID))
	}

	runningInstances := swarmtypes.FilterInstanceById(instances, instanceID)
	if len(runningInstances) == 0 {
		return exitError(errgo.Newf("no more instances left in swarm %s. Cannot update Fleet DNS entry", swarmName))
	}

	if !ignoreQuorumCheck {
		etcdQuorumID, err := ssh.GetEtcd2MemberName(killableInstance.PublicIPAddress)
		if err != nil {
			return exitError(errgo.WithCausef(err, nil, "ssh: failed to check quorum member list: %v", err))
		}

		if etcdQuorumID != "" {
			return exitError(errgo.Newf("Instance %s seems to be part of the etcd quorum. Please remove it beforehand. See %s", killableInstance.Id, etcdDocsLink))
		}
	}

	if err = s.KillInstance(killableInstance); err != nil {
		return exitError(errgo.WithCausef(err, nil, "failed to kill instance: %s", instanceID))
	}

	if changed, err := dns.Update(dnsService, viperConfig.getDNSNamingPattern(), s, runningInstances); err != nil {
		return exitError(errgo.WithCausef(err, nil, "failed to update dns records"))
	} else if !changed {
		return exitError(errgo.Newf("DNS not changed. Couldn't find valid publid DNS name"))
	}

	fmt.Printf(killInstanceSuccessMessage, killableInstance.Id, etcdDocsLink)

	fireNotification()

	return 0
}
开发者ID:giantswarm,项目名称:kocho,代码行数:54,代码来源:kill-instance.go

示例5: getAttributeValuesForWebsites

// getAttributeValuesForWebsites creates a map where the key is the attribute ID and
// each part of the StringEntities slice are the full attribute values for a website ID.
func getAttributeValuesForWebsites(ctx *context) map[string][]codegen.StringEntities {

	var tws store.TableWebsiteSlice
	tws.Load(ctx.dbrConn.NewSession(nil), func(sb *dbr.SelectBuilder) *dbr.SelectBuilder {
		return sb.Where("website_id > 0")
	})

	// key contains the attributeID as a string
	var aws = make(map[string][]codegen.StringEntities)
	tew, err := ctx.aat.TableEavWebsite()
	codegen.LogFatal(err)
	if tew != nil { // only for those who have a wbesite specific table
		for _, w := range tws {
			aCollection, err := codegen.LoadStringEntities(ctx.db, getAttrSelect(ctx, w.WebsiteID))
			codegen.LogFatal(err)
			for _, row := range aCollection {
				if aid, ok := row["attribute_id"]; ok {
					if nil == aws[aid] {
						aws[aid] = make([]codegen.StringEntities, 0, 200) // up to 200 websites at once
					}
					aws[aid] = append(aws[aid], row)
				} else {
					codegen.LogFatal(errgo.Newf("Column attribute_id not found in collection %#v\n", aCollection))
				}
			}
		}
	}
	return aws
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:31,代码来源:attributes.go

示例6: NewConnection

// NewConnection instantiates a Connection for a given database/sql connection
// and event receiver
func NewConnection(opts ...ConnectionOption) (*Connection, error) {
	c := &Connection{
		dn:            DriverNameMySQL,
		EventReceiver: nullReceiver,
	}
	c.ApplyOpts(opts...)

	switch c.dn {
	case DriverNameMySQL:
	default:
		return nil, errgo.Newf("unsupported driver: %s", c.dn)
	}

	if c.DB != nil {
		return c, nil
	}

	if c.dsn != "" {
		var err error
		if c.DB, err = sql.Open(c.dn, c.dsn); err != nil {
			return nil, err
		}
	}
	return c, nil
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:27,代码来源:dbr.go

示例7: Create

// Create creates and returns a Swarm, given a name for the swarm, a ProviderType, and CreateFlags.
func (srv *Service) Create(name string, providerType ProviderType, flags swarmtypes.CreateFlags) (*Swarm, error) {
	p, err := srv.providers.GetByType(providerType)
	if err != nil {
		return nil, err
	}

	switch providerType {
	case AWS:
		if flags.AWSCreateFlags == nil {
			return nil, errgo.Newf("AWSCreateFlags must be provided")
		}
	}

	var cfg string
	if flags.UseIgnition {
		cfg, err = createIgnitionConfig(flags)
	} else {
		cfg, err = createCloudConfig(flags)
	}
	if err != nil {
		return nil, err
	}

	swarm, err := p.CreateSwarm(name, flags, cfg)
	if err != nil {
		return nil, err
	}

	return createSwarm(swarm), nil
}
开发者ID:giantswarm,项目名称:kocho,代码行数:31,代码来源:service.go

示例8: GenerateToken

// GenerateToken creates a new JSON web token. The claims argument will be
// assigned after the registered claim names exp and iat have been set.
// If EnableJTI is false the returned argument jti is empty.
// For details of the registered claim names please see
// http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#rfc.section.4.1
func (a *AuthManager) GenerateToken(claims map[string]interface{}) (token, jti string, err error) {
	now := time.Now()
	t := jwt.New(a.SigningMethod)
	t.Claims["exp"] = now.Add(a.Expire).Unix()
	t.Claims["iat"] = now.Unix()
	for k, v := range claims {
		t.Claims[k] = v
	}
	if a.EnableJTI && a.JTI != nil {
		jti = a.JTI.Get()
		t.Claims["jti"] = jti
	}

	switch t.Method.Alg() {
	case jwt.SigningMethodRS256.Alg(), jwt.SigningMethodRS384.Alg(), jwt.SigningMethodRS512.Alg():
		token, err = t.SignedString(a.rsapk)
	case jwt.SigningMethodES256.Alg(), jwt.SigningMethodES384.Alg(), jwt.SigningMethodES512.Alg():
		token, err = t.SignedString(a.ecdsapk)
	case jwt.SigningMethodHS256.Alg(), jwt.SigningMethodHS384.Alg(), jwt.SigningMethodHS512.Alg():
		token, err = t.SignedString(a.password)
	default:
		return "", "", errgo.Newf("GenerateToken: Unknown algorithm %s", t.Method.Alg())
	}

	return
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:31,代码来源:manager.go

示例9: UnmarshalJSON

// UnmarshalJSON decodes a pair from JSON
func (p *Pair) UnmarshalJSON(data []byte) error {

	var rawPair = struct {
		Value interface{}
		Label string
	}{}

	if err := json.Unmarshal(data, &rawPair); err != nil {
		return errgo.Mask(err)
	}

	p.label = rawPair.Label

	switch vt := rawPair.Value.(type) {
	case string:
		p.NotNull = NotNullString
		p.String = vt
	case float64: // due to the interface{} above int types do not exists
		if math.Abs(vt) < float64(math.MaxInt32) && vt == float64(int64(vt)) { // is int
			p.NotNull = NotNullInt
			p.Int = int(vt)
		} else { // is float
			p.NotNull = NotNullFloat64
			p.Float64 = vt
		}
	case bool:
		p.NotNull = NotNullBool
		p.Bool = vt
	default:
		return errgo.Newf("Cannot detect type for value '%s' in Pair: %#v", rawPair.Value, rawPair)
	}

	return nil
}
开发者ID:joao-parana,项目名称:csfw,代码行数:35,代码来源:pair.go

示例10: Validate

// Validate checks for duplicated configuration paths in all three hierarchy levels.
func (ss SectionSlice) Validate() error {
	if len(ss) == 0 {
		return errgo.New("SectionSlice is empty")
	}
	// @todo try to pick the right strategy between maps and slice depending on the overall size of a full SectionSlice
	var pc = make(utils.StringSlice, ss.TotalFields()) // pc path checker
	i := 0
	for _, s := range ss {
		for _, g := range s.Groups {
			for _, f := range g.Fields {
				arg, err := newArg(Path(s.ID, g.ID, f.ID))
				if err != nil {
					log.Error("config.SectionSlice.Validate.newArg", "err", err, "s", s, "g", g, "f", f)
				}
				p := arg.scopePath()
				if pc.Include(p) {
					return errgo.Newf("Duplicate entry for path %s :: %s", p, ss.ToJSON())
				}
				pc[i] = p
				i++
			}
		}
	}
	return nil
}
开发者ID:postfix,项目名称:csfw,代码行数:26,代码来源:elements_section.go

示例11: GetByCode

// GetByCode returns a CSEntityType using the entity code
func (es CSEntityTypeSlice) GetByCode(code string) (*CSEntityType, error) {
	for _, e := range es {
		if e.EntityTypeCode == code {
			return e, nil
		}
	}
	return nil, errgo.Newf("Entity Code %s not found", code)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:9,代码来源:entity_type.go

示例12: GetByID

// GetByID returns a CSEntityType using the entity id
func (es CSEntityTypeSlice) GetByID(id int64) (*CSEntityType, error) {
	for _, e := range es {
		if e.EntityTypeID == id {
			return e, nil
		}
	}
	return nil, errgo.Newf("Entity ID %d not found", id)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:9,代码来源:entity_type.go

示例13: FindInstanceById

// FindInstanceById searches for an instance in a slice by its id.
func FindInstanceById(instances []Instance, instanceID string) (Instance, error) {
	for _, i := range instances {
		if i.Id == instanceID {
			return i, nil
		}
	}
	return Instance{}, errgo.Newf("couldn't find instance %s", instanceID)
}
开发者ID:giantswarm,项目名称:kocho,代码行数:9,代码来源:instance.go

示例14: Get

func (m entityStoreMap) Get(typeID, storeID int64) (*TableEntityStore, error) {
	entityStoreMutex.RLock()
	defer entityStoreMutex.RUnlock()
	if es, ok := m[getKey(typeID, storeID)]; ok {
		return es, nil
	}
	return nil, errgo.Newf("Key typeID %d storeID %d not found in entity_type map", typeID, storeID)
}
开发者ID:joao-parana,项目名称:csfw,代码行数:8,代码来源:entity_store.go

示例15: Append

// Append adds a table. Overrides silently existing entries.
func (tm *TableManager) Append(i Index, ts *Table) error {
	if ts == nil {
		return errgo.Newf("Table pointer cannot be nil for Index %d", i)
	}
	tm.mu.Lock()
	tm.ts[i] = ts
	tm.mu.Unlock() // use defer once there are multiple returns
	return nil
}
开发者ID:levcom,项目名称:csfw,代码行数:10,代码来源:manager.go


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