Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
26 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
) | ||
|
||
func readDir(dirname string) (ret []*os.FileInfo) { | ||
ret, err := ioutil.ReadDir(dirname) | ||
if err != nil { | ||
// the directory doesn't exist - create it | ||
err = os.MkdirAll(dirname, 0755) | ||
} | ||
return | ||
} | ||
|
||
func walkDir(dirname string, v path.Visitor) { | ||
// first make sure the directory exists | ||
readDir(dirname) | ||
// now walk it | ||
path.Walk(dirname, v, nil) | ||
} | ||
|
||
func readFile(filename string) (contents string) { | ||
contentarry, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
// the file doesn't exist - create the directory and the file | ||
dirname, _ := path.Split(filename) | ||
err = os.MkdirAll(dirname, 0755) | ||
ioutil.WriteFile(filename, []byte{}, 0644) | ||
} | ||
contents = string(contentarry) | ||
return | ||
} |