Ejemplo n.º 1
0
// store returns a TableStore by an id or code.
// The non-empty code has precedence if available.
func (st *Storage) store(r config.ScopeIDer) (*TableStore, error) {
	if r == nil {
		return nil, ErrStoreNotFound
	}
	if c, ok := r.(config.ScopeCoder); ok && c.ScopeCode() != "" {
		return st.stores.FindByCode(c.ScopeCode())
	}
	return st.stores.FindByID(r.ScopeID())
}
Ejemplo n.º 2
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(r config.ScopeIDer) (uint64, error) {
	uz := uint64(0)
	if r == nil {
		return uz, ErrHashRetrieverNil
	}

	if c, ok := r.(config.ScopeCoder); ok && c.ScopeCode() != "" {
		data := []byte(c.ScopeCode())
		var hash uint64 = 14695981039346656037
		for _, c := range data {
			hash ^= uint64(c)
			hash *= 1099511628211
		}
		return hash, nil
	}
	return uint64(r.ScopeID()), nil
}
Ejemplo 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 config.ScopeIDer) (*TableGroup, error) {
	if r == nil {
		return nil, ErrGroupNotFound
	}
	return st.groups.FindByID(r.ScopeID())
}