Exemple #1
0
// ReplaceEnv replaces environemt variables prefixed with '$' in given string.
func ReplaceEnv(s string) string {
	return reEnv.ReplaceAllStringFunc(s, func(t string) string {
		name := t[1:]
		v := os.Getenv(name)
		if len(v) == 0 {
			log.Error("$%s is undefined", name)
		}
		return v
	})
}
Exemple #2
0
func (it *filterIter) Next() (bool, error) {
	if it.closed {
		return false, nil
	}

	// support limit
	if it.limit > 0 && it.count >= it.limit {
		it.close()
		return false, nil
	}

	var k []byte
	var v []byte
	if !it.initialized {
		it.initialized = true
		tk, tv, err := it.init()
		if err != nil {
			return false, err
		}
		k, v = tk, tv
	} else {
		k, v = it.cursor.Next()
	}

	if k == nil {
		it.close()
		return false, nil
	}

	var err = it.filter(&k, &v)
	if err != nil {
		log.Error("filter failed: %v", err)
		return false, err
	}

	if k == nil {
		it.close()
		return false, nil
	}

	it.k = k
	it.v = v

	return true, nil
}
Exemple #3
0
func (it *filterIter) filter(k, v *[]byte) error {
	if it.hasFilter {
		for *k != nil {
			var d map[string]interface{}
			var err = json.Unmarshal(*v, &d)
			if err != nil {
				log.Error("json.Unmarshal failed: %v", err)
				return err
			}
			if it.filterFn(string(*k), d) {
				break
			}
			tk, tv := it.cursor.Next()
			*k = tk
			*v = tv
		}
	}
	if *k != nil {
		it.count++
	}
	return nil
}