Exemplo n.º 1
0
// hash generates the key for the map from either an id int64 or a code string.
// If both interfaces are nil it returns 0 which is default for website, group or store.
// fnv64a used to calculate the uint64 value of a string, especially website code and store code.
func hash(wID scope.WebsiteIDer, gID scope.GroupIDer, sID scope.StoreIDer) (uint64, error) {
	uz := uint64(0)
	if nil == wID && nil == gID && nil == sID {
		return uz, ErrHashRetrieverNil
	}

	if wC, ok := wID.(scope.WebsiteCoder); ok {
		return hashCode(wC.WebsiteCode()), nil
	}
	if nil != wID {
		return uint64(wID.WebsiteID()), nil
	}

	if nil != gID {
		return uint64(gID.GroupID()), nil
	}

	if sC, ok := sID.(scope.StoreCoder); ok {
		return hashCode(sC.StoreCode()), nil
	}
	if nil != sID {
		return uint64(sID.StoreID()), nil
	}
	return uz, ErrHashRetrieverNil // unreachable ....
}
Exemplo n.º 2
0
// Group creates a new Group which contains all related stores and its website according to the
// interface definition.
func (st *Storage) Group(id scope.GroupIDer) (*Group, error) {
	g, err := st.group(id)
	if err != nil {
		return nil, errgo.Mask(err)
	}

	w, err := st.website(scope.MockID(g.WebsiteID))
	if err != nil {
		if PkgLog.IsDebug() {
			PkgLog.Debug("store.Storage.Group.website", "err", err, "websiteID", g.WebsiteID, "groupID", id.GroupID())
		}
		return nil, errgo.Mask(err)
	}
	return NewGroup(g, SetGroupConfig(st.cr), SetGroupWebsite(w), SetGroupStores(st.stores, nil))
}
Exemplo n.º 3
0
// group returns a TableGroup by using a group id as argument. If no argument or more than
// one has been supplied it returns an error.
func (st *Storage) group(r scope.GroupIDer) (*TableGroup, error) {
	if r == nil {
		return nil, ErrGroupNotFound
	}
	return st.groups.FindByGroupID(r.GroupID())
}