func (h *MyHook) PreRead(path string, length int64, offset int64) ([]byte, bool, hookfs.HookContext, error) {
	ctx := MyHookContext{path: path}
	if probab(3) {
		sleep := 3 * time.Second
		log.WithFields(log.Fields{
			"h":     h,
			"ctx":   ctx,
			"sleep": sleep,
		}).Info("MyPreRead: sleeping")
		time.Sleep(sleep)
	}
	return nil, false, ctx, nil
}
PreRead implements hookfs.HookOnRead
package example
import (
	"math/rand"
	"syscall"
	"time"
	hookfs "github.com/osrg/hookfs/pkg/hookfs"
	log "github.com/sirupsen/logrus"
)
type MyHookContext struct {
	path string
}
type MyHook struct{}
func (h *MyHook) Init() error {
	log.WithFields(log.Fields{
		"h": h,
	}).Info("MyInit: initializing")
	return nil
}
func (h *MyHook) PreOpen(path string, flags uint32) (bool, hookfs.HookContext, error) {
	ctx := MyHookContext{path: path}
	if probab(5) {
		log.WithFields(log.Fields{
			"h":   h,
			"ctx": ctx,
		}).Info("MyPreOpen: returning EIO")
		return true, ctx, syscall.EIO
	}
	return false, ctx, nil
}
func (h *MyHook) PostOpen(realRetCode int32, ctx hookfs.HookContext) (bool, error) {
	if probab(5) {
		log.WithFields(log.Fields{
			"h":   h,
			"ctx": ctx,
		}).Info("MyPostOpen: returning EPERM")
		return true, syscall.EPERM
	}
	return false, nil
}