func ClearView(view *BarrierView) error {
	keys, err := CollectKeys(view)
	if err != nil {
		return err
	}
	for _, key := range keys {
		if err := view.Delete(key); err != nil {
			return err
		}
	}
	return nil
}
ClearView is used to delete all the keys in a view
package vault
import (
	"fmt"
	"strings"
	"github.com/hashicorp/vault/logical"
)
type BarrierView struct {
	barrier BarrierStorage
	prefix  string
}
func NewBarrierView(barrier BarrierStorage, prefix string) *BarrierView {
	return &BarrierView{
		barrier: barrier,
		prefix:  prefix,
	}
}
func (v *BarrierView) sanityCheck(key string) error {
	if strings.Contains(key, "..") {
		return fmt.Errorf("key cannot be relative path")
	}
	return nil
}
func (v *BarrierView) List(prefix string) ([]string, error) {
	if err := v.sanityCheck(prefix); err != nil {
		return nil, err
	}
	return v.barrier.List(v.expandKey(prefix))
}
func (v *BarrierView) Get(key string) (*logical.StorageEntry, error) {
	if err := v.sanityCheck(key); err != nil {
		return nil, err
	}
	entry, err := v.barrier.Get(v.expandKey(key))
	if err != nil {
		return nil, err
	}
	if entry == nil {
		return nil, nil
	}
	if entry != nil {
		entry.Key = v.truncateKey(entry.Key)
	}
	return &logical.StorageEntry{
		Key:   entry.Key,
		Value: entry.Value,
	}, nil
}
func (v *BarrierView) Put(entry *logical.StorageEntry) error {
	if err := v.sanityCheck(entry.Key); err != nil {
		return err
	}
	nested := &Entry{
		Key:   v.expandKey(entry.Key),
		Value: entry.Value,
	}
	return v.barrier.Put(nested)
}
func (v *BarrierView) Delete(key string) error {
	if err := v.sanityCheck(key); err != nil {
		return err
	}
	return v.barrier.Delete(v.expandKey(key))
}
func (v *BarrierView) SubView(prefix string) *BarrierView {
	sub := v.expandKey(prefix)
	return &BarrierView{barrier: v.barrier, prefix: sub}
}
func (v *BarrierView) expandKey(suffix string) string {
	return v.prefix + suffix
}
func (v *BarrierView) truncateKey(full string) string {
	return strings.TrimPrefix(full, v.prefix)
}
func ScanView(view *BarrierView, cb func(path string)) error {
	frontier := []string{""}
	for len(frontier) > 0 {
		n := len(frontier)
		current := frontier[n-1]
		frontier = frontier[:n-1]
		contents, err := view.List(current)
		if err != nil {
			return fmt.Errorf("list failed at path '%s': %v", current, err)
		}
		for _, c := range contents {
			fullPath := current + c
			if strings.HasSuffix(c, "/") {
				frontier = append(frontier, fullPath)
			} else {
				cb(fullPath)
			}
		}
	}
	return nil
}
func CollectKeys(view *BarrierView) ([]string, error) {
	var existing []string
	cb := func(path string) {
		existing = append(existing, path)
	}
	if err := ScanView(view, cb); err != nil {
		return nil, err
	}
	return existing, nil
}