Skip to content

Instantly share code, notes, and snippets.

@afrikaan-official
Created October 20, 2017 13:26
Show Gist options
  • Save afrikaan-official/242bc4cf1c11da50c6a6cb13099215cf to your computer and use it in GitHub Desktop.
Save afrikaan-official/242bc4cf1c11da50c6a6cb13099215cf to your computer and use it in GitHub Desktop.
testable dir.go file
package service
import "os"
type DirExistCreator interface {
Exist(path string) bool
Create(path string) bool
}
type DirService struct{}
func (d *DirService) Exist(path string) bool {
if _, e := os.Stat(path); os.IsNotExist(e) {
return false
}
return true
}
func (d *DirService) Create(path string) bool {
if !d.Exist(path) {
return d.Create(path)
}
return false
}
func NewDirService() *DirService {
return &DirService{}
}
func Exist(d DirExistCreator, path string) bool {
return d.Exist(path)
}
func Create(d DirExistCreator, path string) bool {
return d.Create(path)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment