Skip to content

Commit

Permalink
Merge pull request #35 from Clivern/feature/add-ensuredir
Browse files Browse the repository at this point in the history
Feature/add ensuredir
  • Loading branch information
Clivern authored Jun 21, 2019
2 parents 68b880f + 3111af3 commit bd84f80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p align="center">
<a href="https://godoc.org/github.com/clivern/hippo"><img src="https://godoc.org/github.com/clivern/hippo?status.svg"></a>
<a href="https://travis-ci.org/Clivern/Hippo"><img src="https://travis-ci.org/Clivern/Hippo.svg?branch=master"></a>
<a href="https://github.com/Clivern/Hippo/releases"><img src="https://img.shields.io/badge/Version-1.5.0-red.svg"></a>
<a href="https://github.com/Clivern/Hippo/releases"><img src="https://img.shields.io/badge/Version-1.5.1-red.svg"></a>
<a href="https://goreportcard.com/report/github.com/Clivern/Hippo"><img src="https://goreportcard.com/badge/github.com/Clivern/Hippo?v=1.0.0"></a>
<a href="https://github.com/Clivern/Hippo/blob/master/LICENSE"><img src="https://img.shields.io/badge/LICENSE-MIT-orange.svg"></a>
</p>
Expand Down Expand Up @@ -279,6 +279,9 @@ exists := hippo.FileExists("/var/log/error.log")

// check if dir exists
exists := hippo.DirExists("/var/log")

// ensure that dir exists
exists, err := hippo.EnsureDir("/var/log", 755)
```

**Latency Tracker Component**
Expand Down
10 changes: 10 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ func DirExists(path string) bool {
}
return false
}

// EnsureDir ensures that directory exists
func EnsureDir(dirName string, mode int) (bool, error) {
err := os.MkdirAll(dirName, os.FileMode(mode))

if err == nil || os.IsExist(err) {
return true, nil
}
return false, err
}

0 comments on commit bd84f80

Please sign in to comment.