Last active
April 24, 2018 01:49
-
-
Save Natata/fa4a3ca988a132554d2c4cea0e41dc5c to your computer and use it in GitHub Desktop.
function for create or open a 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
func createOrOpenFile(dir, fn string) (*os.File, error) { | |
if _, err := os.Stat(dir); os.IsNotExist(err) { | |
err := os.Mkdir(dir, 0700) | |
if err != nil { | |
log.Infof("mkdir %v fail", dir) | |
return nil, err | |
} | |
} | |
fallPath := filepath.Join(dir, fn) | |
return os.OpenFile(fallPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment