Example #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 ....
}
Example #2
0
// website returns a TableWebsite by using either id or code to find it. If id and code are
// available then the non-empty code has precedence.
func (st *Storage) website(r scope.WebsiteIDer) (*TableWebsite, error) {
	if r == nil {
		return nil, ErrWebsiteNotFound
	}
	if c, ok := r.(scope.WebsiteCoder); ok && c.WebsiteCode() != "" {
		return st.websites.FindByCode(c.WebsiteCode())
	}
	return st.websites.FindByWebsiteID(r.WebsiteID())
}