Skip to content

Instantly share code, notes, and snippets.

@HaiTo
Last active December 28, 2016 04:26
Show Gist options
  • Save HaiTo/8c2ea981600db1de303a9fec8e052c87 to your computer and use it in GitHub Desktop.
Save HaiTo/8c2ea981600db1de303a9fec8e052c87 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
homedir "github.com/mitchellh/go-homedir"
"os"
"time"
)
func main() {
dir, _ := homedir.Dir()
path := dir + "/,/" + time.Now().Format("20060102") + ".md"
// check file
_, exists_err := os.Stat(path)
if !os.IsNotExist(exists_err) {
fmt.Println("already created file is : " + path)
os.Exit(1)
}
// create file
if _, err := os.Create(path); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(path)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment