• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang errgo.Mask函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: RemoveInstanceFromDiscovery

// RemoveInstanceFromDiscovery removes an instance from etcd discovery.
func RemoveInstanceFromDiscovery(i swarmtypes.Instance) error {
	etcdMemberName, err := ssh.GetEtcd2MemberName(i.PublicIPAddress)
	if err != nil {
		return errgo.Mask(err)
	}
	// Not a quorum member
	if etcdMemberName == "" {
		return nil
	}

	discoveryUrl, err := ssh.GetEtcdDiscoveryUrl(i.PublicIPAddress)
	if err != nil {
		return errgo.Mask(err)
	}

	machineUrl := discoveryUrl + "/" + etcdMemberName
	req, err := http.NewRequest("DELETE", machineUrl, nil)
	if err != nil {
		return errgo.Mask(err)
	}

	_, err = http.DefaultClient.Do(req)
	if err != nil {
		return errgo.Mask(err)
	}
	return nil
}
开发者ID:giantswarm,项目名称:kocho,代码行数:28,代码来源:etcd-service-discovery.go


示例17: Init

// Init initializes the appStore from a scope code and a scope type.
// This function is mainly used when booting the app to set the environment configuration
// Also all other calls to any method receiver with nil arguments depends on the appStore.
// @see \Magento\Store\Model\StorageFactory::_reinitStores
func (sm *Manager) Init(scopeCode config.ScopeIDer, scopeType config.ScopeGroup) error {
	if sm.appStore != nil {
		return ErrAppStoreSet
	}
	var err error
	switch scopeType {
	case config.ScopeStoreID:
		sm.appStore, err = sm.Store(scopeCode)
	case config.ScopeGroupID:
		g, errG := sm.Group(scopeCode) // this is the group_id
		if errG != nil {
			return errgo.Mask(errG)
		}
		sm.appStore, err = g.DefaultStore()
		break
	case config.ScopeWebsiteID:
		w, errW := sm.Website(scopeCode)
		if errW != nil {
			return errgo.Mask(errW)
		}
		sm.appStore, err = w.DefaultStore()
		break
	default:
		return ErrUnsupportedScopeGroup
	}
	return errgo.Mask(err)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:31,代码来源:manager.go


示例18: LoadAuthorize

// LoadAuthorize looks up AuthorizeData by a code.
// Client information MUST be loaded together.
// Optionally can return error if expired.
func (s *Storage) LoadAuthorize(code string) (*osin.AuthorizeData, error) {
	var (
		mdata  authorizeData
		client *Client
	)

	err := s.authData.Find(bson.M{"code": code}).One(&mdata)
	if err == mgo.ErrNotFound {
		return nil, nil
	}
	if err != nil {
		return nil, errgo.Mask(err)
	}

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

	data := &osin.AuthorizeData{
		Client:      client,
		Code:        mdata.Code,
		ExpiresIn:   mdata.ExpiresIn,
		Scope:       mdata.Scope,
		RedirectUri: mdata.RedirectUri,
		State:       mdata.State,
		CreatedAt:   mdata.Created,
	}

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


示例19: InitByRequest

// InitByRequest returns a new Store read from a cookie or HTTP request param.
// The internal appStore must be set before hand.
// 1. check cookie store, always a string and the store code
// 2. check for ___store variable, always a string and the store code
// 3. May return nil,nil if nothing is set.
// This function must be used within an HTTP handler.
// The returned new Store must be used in the HTTP context and overrides the appStore.
// @see \Magento\Store\Model\StorageFactory::_reinitStores
func (sm *Manager) InitByRequest(res http.ResponseWriter, req *http.Request, scopeType config.ScopeGroup) (*Store, error) {
	if sm.appStore == nil {
		// that means you must call Init() before executing this function.
		return nil, ErrAppStoreNotSet
	}

	var reqStore *Store
	if keks := GetCodeFromCookie(req); keks != nil {
		reqStore, _ = sm.GetRequestStore(keks, scopeType) // ignore errors
	}

	if reqStoreCode := req.URL.Query().Get(HTTPRequestParamStore); reqStoreCode != "" {
		var err error
		// @todo reqStoreCode if number ... cast to int64 because then group id if ScopeGroup is group.
		if reqStore, err = sm.GetRequestStore(config.ScopeCode(reqStoreCode), scopeType); err != nil {
			return nil, errgo.Mask(err)
		}
		// also delete and re-set a new cookie
		if reqStore != nil && reqStore.Data().Code.String == reqStoreCode {
			wds, err := reqStore.Website().DefaultStore()
			if err != nil {
				return nil, errgo.Mask(err)
			}
			if wds.Data().Code.String == reqStoreCode {
				reqStore.DeleteCookie(res) // cookie not needed anymore
			} else {
				reqStore.SetCookie(res) // make sure we force set the new store
			}
		}
	}
	return reqStore, nil // can be nil,nil
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:40,代码来源:manager.go


示例20: Init

// Init loads the column definitions from the database for each table. Set reInit
// to true to allow reloading otherwise it loads only once.
func (tm *TableManager) Init(dbrSess dbr.SessionRunner, reInit ...bool) error {
	reLoad := false
	if len(reInit) > 0 {
		reLoad = reInit[0]
	}
	if true == tm.initDone && false == reLoad {
		return nil
	}
	if false == tm.initDone && true == reLoad {
		return errgo.Mask(ErrManagerInitReload)
	}
	tm.mu.Lock()
	defer tm.mu.Unlock()
	tm.initDone = true

	for _, table := range tm.ts {
		if err := table.LoadColumns(dbrSess); err != nil {
			if PkgLog.IsDebug() {
				PkgLog.Debug("csdb.TableManager.Init.LoadColumns", "err", err, "table", table)
			}
			return errgo.Mask(err)
		}
	}

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errgo.MaskFunc函数代码示例发布时间:2022-05-23
下一篇:
Golang errgo.Cause函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap