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.
35 lines
502 B
35 lines
502 B
3 years ago
|
package cmd
|
||
3 years ago
|
|
||
|
import (
|
||
|
"errors"
|
||
3 years ago
|
"isthisnagee.com/tools/diary/model"
|
||
3 years ago
|
"log"
|
||
|
"os"
|
||
|
"path"
|
||
|
)
|
||
|
|
||
3 years ago
|
var App *model.App
|
||
|
|
||
|
func InitApp() {
|
||
3 years ago
|
|
||
|
home_dir, err := os.UserHomeDir()
|
||
|
if err != nil {
|
||
|
log.Fatal(err.Error())
|
||
|
}
|
||
|
|
||
3 years ago
|
var db_path = path.Join(home_dir, ".diary.sql")
|
||
3 years ago
|
|
||
|
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())
|
||
|
}
|
||
3 years ago
|
var app = model.NewApp(db_path)
|
||
|
App = &app
|
||
3 years ago
|
}
|