You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diary/cmd/util.go

35 lines
502 B

package cmd
import (
"errors"
"isthisnagee.com/tools/diary/model"
"log"
"os"
"path"
)
var App *model.App
func InitApp() {
home_dir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err.Error())
}
var db_path = path.Join(home_dir, ".diary.sql")
if _, err := os.Stat(db_path); errors.Is(err, os.ErrNotExist) {
_, err := os.Create(db_path)
if err != nil {
log.Fatal(err.Error())
}
}
if err != nil {
log.Fatal(err.Error())
}
var app = model.NewApp(db_path)
App = &app
}