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
// store returns a TableStore by an id or code.
// The non-empty code has precedence if available.
func (st *Storage) store(r scope.StoreIDer) (*TableStore, error) {
	if r == nil {
		return nil, ErrStoreNotFound
	}
	if c, ok := r.(scope.StoreCoder); ok && c.StoreCode() != "" {
		return st.stores.FindByCode(c.StoreCode())
	}
	return st.stores.FindByStoreID(r.StoreID())
}
Exemplo n.º 3
0
// ShowNonRequiredState
func ShowNonRequiredState(cr config.Reader, r scope.StoreIDer) bool {
	return cr.GetBool(config.ScopeStore(r.StoreID()), config.Path(PathDisplayAllStates))
}