Created
October 20, 2017 13:26
-
-
Save afrikaan-official/242bc4cf1c11da50c6a6cb13099215cf to your computer and use it in GitHub Desktop.
testable dir.go file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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