github.com/acornpublishing/functional-programming-go@v0.0.0-20220401005601-c3bd3786d5a1/Chapter06/04_onion/src/interfaces/localstorage.go (about) 1 package interfaces 2 3 type LocalHandler interface { 4 FileExists(fileName string) (fileExists bool, err error) 5 } 6 7 type LocalRepo struct { 8 localHandlers map[string]LocalHandler 9 localHandler LocalHandler 10 } 11 12 type LocalFileSystemRepo LocalRepo 13 14 func NewLocalRepo(localHandlers map[string]LocalHandler) *LocalFileSystemRepo { 15 localRepo := new(LocalFileSystemRepo) 16 localRepo.localHandlers = localHandlers 17 localRepo.localHandler = localHandlers["LocalFileSystemRepo"] 18 return localRepo 19 } 20 21 func (repo *LocalFileSystemRepo) FileExists(fileName string) (fileExists bool, err error) { 22 return repo.localHandler.FileExists(fileName) 23 }