func (ekv *EntityKV) del(e, de *pb.Entity) error {
	if len(de.GetMeta().GetKV()) != 1 {
		return tree.ErrFailedPrecondition
	}
	compare := de.GetMeta().GetKV()[0].GetKey()
	out := []*pb.KVData{}
	for _, k := range e.GetMeta().GetKV() {
		if k.GetKey() == compare {
			continue
		}
		out = append(out, k)
	}
	if len(out) == len(e.GetMeta().GetKV()) {
		return tree.ErrNoSuchKey
	}
	e.Meta.KV = out
	return nil
}
del looks for the specified key and tries to remove it, returning
an error if it does not exist.
package hooks
import (
	"github.com/netauth/netauth/internal/startup"
	"github.com/netauth/netauth/internal/tree"
	pb "github.com/netauth/protocol"
)
func init() {
	startup.RegisterCallback(entitykvcb)
}
type EntityKV struct {
	tree.BaseHook
	do func(*pb.Entity, *pb.Entity) error
}
func (ekv *EntityKV) Run(e, de *pb.Entity) error {
	return ekv.do(e, de)
}
func (ekv *EntityKV) add(e, de *pb.Entity) error {
	if len(de.GetMeta().GetKV()) != 1 {
		return tree.ErrFailedPrecondition
	}
	compare := de.GetMeta().GetKV()[0].GetKey()
	for _, k := range e.GetMeta().GetKV() {
		if k.GetKey() == compare {
			return tree.ErrKeyExists
		}
	}
	e.Meta.KV = append(e.Meta.KV, de.GetMeta().GetKV()[0])
	return nil
}