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


Golang errgo.Mask函数代码示例

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


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

示例1: deleteEntries

// deleteEntries deletes DNS entries, given a stack name, and list of Entries to delete.
func (cli *CloudFlareDNS) deleteEntries(name string, e *Entries) error {
	ctx := context.TODO()

	client := cli.client()

	// First we need to find our zone
	zone, err := cli.findZone(ctx, e.Zone)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	records, err := client.Records.List(ctx, zone.ID)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	for _, record := range records {
		entriesRecord := record.Name == e.Catchall ||
			record.Name == e.CatchallPrivate ||
			record.Name == e.Public ||
			record.Name == e.Private ||
			record.Name == e.Fleet
		if entriesRecord {
			if err := client.Records.Delete(ctx, zone.ID, record.ID); err != nil {
				return errgo.Mask(err, errgo.Any)
			}
		}
	}
	return nil
}
开发者ID:giantswarm,项目名称:kocho,代码行数:31,代码来源:cloudflare.go

示例2: render

// fetches or catches result of fn as JSON, and renders JSON to response
func (m *memcacheCache) render(w http.ResponseWriter, status int, key string, fn func() (interface{}, error)) error {

	var write = func(value []byte) error {
		return writeBody(w, value, status, "application/json")
	}

	key = makeCacheKey(key)

	it, err := m.mc.Get(key)
	if err == nil {
		return write(it.Value)
	} else if err != memcache.ErrCacheMiss {
		return errgo.Mask(err)
	}
	obj, err := fn()
	if err != nil {
		return err
	}
	value, err := m.set(key, obj)
	if err != nil {
		return errgo.Mask(err)
	}
	return write(value)

}
开发者ID:sandbreaker,项目名称:photoshare,代码行数:26,代码来源:cache.go

示例3: parseParametersTemplate

func parseParametersTemplate(templatePath string, p parameters) (string, error) {
	f, err := os.Create(generatedParametersPath)
	if err != nil {
		return generatedParametersPath, errgo.Mask(err)
	}
	defer func() {
		if err := f.Close(); err != nil {
			panic(err)
		}
	}()

	absoluteParametersTemplatePath, err := filepath.Abs(templatePath)
	if err != nil {
		return "", errgo.Mask(err)
	}

	templateData, err := ioutil.ReadFile(absoluteParametersTemplatePath)
	if err != nil {
		return "", errgo.Mask(err)
	}

	var tmpl *template.Template
	if tmpl, err = template.New("cfg").Parse(string(templateData)); err != nil {
		return generatedParametersPath, errgo.Mask(err)
	}

	if err = tmpl.Execute(f, p); err != nil {
		return generatedParametersPath, errgo.Mask(err)
	}

	return generatedParametersPath, nil
}
开发者ID:giantswarm,项目名称:kocho,代码行数:32,代码来源:parameters.go

示例4: InitEntityStoreMap

func InitEntityStoreMap(dbrSess *dbr.Session) error {
	if atomic.LoadUint32(&initMapDone.done) == 1 {
		return ErrStoreMapInitialized
	}

	initMapDone.m.Lock()
	defer initMapDone.m.Unlock()
	if initMapDone.done == 0 {
		defer atomic.StoreUint32(&initMapDone.done, 1)

		s, err := TableCollection.Structure(TableIndexEntityStore)
		if err != nil {
			return errgo.Mask(err)
		}
		var ess TableEntityStoreSlice
		_, err = dbrSess.
			Select(s.Columns.FieldNames()...).
			From(s.Name).
			LoadStructs(&ess)
		if err != nil {
			return errgo.Mask(err)
		}

		for _, es := range ess {
			EntityStoreMap.Set(es.EntityTypeID, es.StoreID, es)
		}

		ess = ess[:len(ess)-1] // delete Struct Slice https://code.google.com/p/go-wiki/wiki/SliceTricks
		return nil
	}
	return ErrStoreMapInitialized
}
开发者ID:joao-parana,项目名称:csfw,代码行数:32,代码来源:entity_store.go

示例5: SQLQueryToColumns

// SQLQueryToColumns generates from a SQL query an array containing all the column properties.
// dbSelect argument can be nil but then you must provide query strings which will be joined to the final query.
func SQLQueryToColumns(db *sql.DB, dbSelect *dbr.SelectBuilder, query ...string) (Columns, error) {

	tableName := "tmp_" + randSeq(20)
	dropTable := func() {
		_, err := db.Exec("DROP TABLE IF EXISTS `" + tableName + "`")
		if err != nil {
			panic(err)
		}
	}
	dropTable()
	defer dropTable()

	qry := strings.Join(query, " ")
	var args []interface{}
	if qry == "" && dbSelect != nil {
		var err error
		qry, args, err = dbSelect.ToSql()
		if err != nil {
			return nil, errgo.Mask(err)
		}
	}
	_, err := db.Exec("CREATE TABLE `"+tableName+"` AS "+qry, args...)
	if err != nil {
		return nil, errgo.Mask(err)
	}

	return GetColumns(db, tableName)
}
开发者ID:joao-parana,项目名称:csfw,代码行数:30,代码来源:database.go

示例6: LoadStringEntities

// LoadStringEntities executes a SELECT query and returns a slice containing columns names and its string values
func LoadStringEntities(db *sql.DB, dbSelect *dbr.SelectBuilder) ([]StringEntities, error) {

	qry, args, err := dbSelect.ToSql()
	if err != nil {
		return nil, errgo.Mask(err)
	}

	rows, err := db.Query(qry, args...)
	if err != nil {
		return nil, errgo.Mask(err)
	}
	defer rows.Close()

	columnNames, err := rows.Columns()
	if err != nil {
		return nil, errgo.Mask(err)
	}

	ret := make([]StringEntities, 0, 2000)
	rss := newRowTransformer(columnNames)
	for rows.Next() {

		if err := rows.Scan(rss.cp...); err != nil {
			return nil, errgo.Mask(err)
		}
		err := rss.toString()
		if err != nil {
			return nil, errgo.Mask(err)
		}
		rss.append(&ret)
	}
	return ret, nil
}
开发者ID:joao-parana,项目名称:csfw,代码行数:34,代码来源:database.go

示例7: getUserInfo

func (a *defaultAuthenticator) getUserInfo(r *http.Request, providerName string) (*authInfo, error) {
	provider, err := a.getAuthProvider(r, providerName)
	if err != nil {
		return nil, errgo.Mask(err)
	}
	m := make(objx.Map)
	if r.Form == nil {
		r.ParseForm()
	}
	for k, v := range r.Form {
		m.Set(k, v)
	}
	creds, err := provider.CompleteAuth(m)
	if err != nil {
		return nil, errgo.Mask(err)
	}
	user, err := provider.GetUser(creds)
	if err != nil {
		return nil, errgo.Mask(err)
	}
	info := &authInfo{
		name:  user.Name(),
		email: user.Email(),
	}

	return info, nil
}
开发者ID:sandbreaker,项目名称:photoshare,代码行数:27,代码来源:auth.go

示例8: GetColumns

// GetColumns returns all columns from a table. It discards the column
// entity_type_id from some entity tables. The column attribute_model will also
// be dropped from table eav_attribute
func GetColumns(db *sql.DB, table string) (Columns, error) {
	var cols = make(Columns, 0, 200)
	rows, err := db.Query("SHOW COLUMNS FROM `" + table + "`")
	if err != nil {
		return nil, errgo.Mask(err)
	}
	defer rows.Close()

	col := column{}
	for rows.Next() {

		err := rows.Scan(&col.Field, &col.Type, &col.Null, &col.Key, &col.Default, &col.Extra)
		if err != nil {
			return nil, errgo.Mask(err)
		}
		if isIgnoredColumn(table, col.Field.String) {
			continue
		}
		cols = append(cols, col)
	}
	err = rows.Err()
	if err != nil {
		return nil, errgo.Mask(err)
	}
	return cols, nil
}
开发者ID:joao-parana,项目名称:csfw,代码行数:29,代码来源:database.go

示例9: getEntityTypeData

// getEntityTypeData retrieves all EAV models from table eav_entity_type but only those listed in variable
// codegen.ConfigEntityType. It then applies the mapping data from codegen.ConfigEntityType to the entity_type struct.
// Depends on generated code from tableToStruct.
func getEntityTypeData(dbrSess *dbr.Session) (etc eav.TableEntityTypeSlice, err error) {

	s, err := eav.TableCollection.Structure(eav.TableIndexEntityType)
	if err != nil {
		return nil, errgo.Mask(err)
	}

	_, err = dbrSess.
		Select(s.AllColumnAliasQuote(s.Name)...).
		From(s.Name).
		Where("entity_type_code IN ?", codegen.ConfigEntityType.Keys()).
		LoadStructs(&etc)
	if err != nil {
		return nil, errgo.Mask(err)
	}

	for typeCode, mapData := range codegen.ConfigEntityType {
		// map the fields from the config struct to the data retrieved from the database.
		et, err := etc.GetByCode(typeCode)
		codegen.LogFatal(err)
		et.EntityModel = codegen.ParseString(mapData.EntityModel, et)
		et.AttributeModel.String = codegen.ParseString(mapData.AttributeModel, et)
		et.EntityTable.String = codegen.ParseString(mapData.EntityTable, et)
		et.IncrementModel.String = codegen.ParseString(mapData.IncrementModel, et)
		et.AdditionalAttributeTable.String = codegen.ParseString(mapData.AdditionalAttributeTable, et)
		et.EntityAttributeCollection.String = codegen.ParseString(mapData.EntityAttributeCollection, et)
	}

	return etc, nil
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:33,代码来源:entity_type.go

示例10: LoadAccess

// LoadAccess retrieves access data by token. Client information MUST be loaded together.
// AuthorizeData and AccessData DON'T NEED to be loaded if not easily available.
// Optionally can return error if expired.
func (s *Storage) LoadAccess(token string) (*osin.AccessData, error) {
	var (
		data   *accessData
		client *Client
	)

	err := s.accessData.Find(bson.M{"accesstoken": token}).One(&data)
	if err == mgo.ErrNotFound {
		return nil, nil
	}
	if err != nil {
		return nil, errgo.Mask(err)
	}

	err = s.clients.FindId(data.ClientID).One(&client)
	if err == mgo.ErrNotFound {
		return nil, nil
	}
	if err != nil {
		return nil, errgo.Mask(err)
	}

	d := &osin.AccessData{
		Client:       client,
		AccessToken:  data.AccessToken,
		RefreshToken: data.RefreshToken,
		Scope:        data.Scope,
		RedirectUri:  data.RedirectUri,
		CreatedAt:    data.CreatedAt,
		ExpiresIn:    data.ExpiresIn,
		UserData:     data,
	}

	return d, nil
}
开发者ID:fd,项目名称:mauth,代码行数:38,代码来源:storage.go

示例11: getPhotoDetail

func (d *defaultDataMapper) getPhotoDetail(photoID int64, user *user) (*photoDetail, error) {

	photo := &photoDetail{}

	if photoID == 0 {
		return photo, sql.ErrNoRows
	}

	q := "SELECT p.*, u.name AS owner_name " +
		"FROM photos p JOIN users u ON u.id = p.owner_id " +
		"WHERE p.id=$1"

	if err := d.SelectOne(photo, q, photoID); err != nil {
		return photo, errgo.Mask(err)
	}

	var tags []tag

	if _, err := d.Select(&tags,
		"SELECT t.* FROM tags t JOIN photo_tags pt ON pt.tag_id=t.id "+
			"WHERE pt.photo_id=$1", photo.ID); err != nil {
		return photo, errgo.Mask(err)
	}
	for _, tag := range tags {
		photo.Tags = append(photo.Tags, tag.Name)
	}

	photo.Permissions = &permissions{
		photo.canEdit(user),
		photo.canDelete(user),
		photo.canVote(user),
	}
	return photo, nil

}
开发者ID:sandbreaker,项目名称:photoshare,代码行数:35,代码来源:database.go

示例12: updateTags

func (t *transaction) updateTags(photo *photo) error {

	var (
		args    = []string{"$1"}
		params  = []interface{}{interface{}(photo.ID)}
		isEmpty = true
		counter = 1
	)
	for _, name := range photo.Tags {
		name = strings.TrimSpace(name)
		if name != "" {
			counter++
			args = append(args, fmt.Sprintf("$%d", counter))
			params = append(params, interface{}(strings.ToLower(name)))
			isEmpty = false
		}
	}

	if isEmpty && photo.ID != 0 {
		_, err := t.Exec("DELETE FROM photo_tags WHERE photo_id=$1", photo.ID)
		return errgo.Mask(err)
	}
	if _, err := t.Exec(fmt.Sprintf("SELECT add_tags(%s)", strings.Join(args, ",")), params...); err != nil {
		return errgo.Mask(err)
	}
	return nil

}
开发者ID:sandbreaker,项目名称:photoshare,代码行数:28,代码来源:database.go

示例13: WithIsCountryAllowedByIP

// WithIsCountryAllowedByIP a more advanced function. It expects from the context
// the store.ManagerReader ...
func (s *Service) WithIsCountryAllowedByIP() ctxhttp.Middleware {
	return func(h ctxhttp.Handler) ctxhttp.Handler {
		return ctxhttp.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {

			_, requestedStore, err := store.FromContextReader(ctx)
			if err != nil {
				if PkgLog.IsDebug() {
					PkgLog.Debug("geoip.WithCountryByIP.FromContextManagerReader", "err", err)
				}
				return errgo.Mask(err)
			}

			var ipCountry *IPCountry
			ctx, ipCountry, err = s.newContextCountryByIP(ctx, r)
			if err != nil {
				ctx = NewContextWithError(ctx, err)
				return h.ServeHTTPContext(ctx, w, r)
			}

			allowedCountries, err := directory.AllowedCountries(requestedStore.Config)
			if err != nil {
				if PkgLog.IsDebug() {
					PkgLog.Debug("geoip.WithCountryByIP.directory.AllowedCountries", "err", err, "st.Config", requestedStore.Config)
				}
				return errgo.Mask(err)
			}

			if false == s.IsAllowed(requestedStore, ipCountry, allowedCountries, r) {
				h = s.altHandlerByID(requestedStore)
			}

			return h.ServeHTTPContext(ctx, w, r)
		})
	}
}
开发者ID:levcom,项目名称:csfw,代码行数:37,代码来源:service.go

示例14: 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

示例15: 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


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