Example #1
0
File: init.go Project: Ganben/blog
func InitAction(ctx *cli.Context) {
	t := time.Now()
	// check config,
	// is install time > 0, show installed message
	// otherwise, set install time and write new config file
	if app.Config.AppInstallTime > 0 {
		log.Info("Blog|Installed|%s", time.Unix(app.Config.AppInstallTime, 0).Format(time.RFC3339))
		return
	}
	app.Config.AppInstallTime = time.Now().Unix()
	app.Config.Write()

	// make directories
	os.Mkdir(app.Config.UserDirectory, os.ModePerm)
	os.Mkdir(filepath.Join(app.Config.UserDirectory, app.Config.UserThemeDirectory), os.ModePerm)
	os.Mkdir(filepath.Join(app.Config.UserDirectory, app.Config.UserUploadDirectory), os.ModePerm)

	// init database schema
	app.Db = core.NewDatabase(filepath.Join(app.Config.UserDirectory, app.Config.UserDataFile))
	action.Call(InitDbSchema, nil)
	action.Call(InitDbDefault, nil)

	log.Info("Blog|Install|Success|%.1fms", time.Since(t).Seconds()*1000)

}
Example #2
0
File: serv.go Project: Ganben/blog
func ServAction(ctx *cli.Context) {
	t := time.Now()
	address := fmt.Sprintf("%s:%s", app.Config.HttpHost, app.Config.HttpAddress)
	log.Info("Serv|Begin|%s", address)

	// init global vars
	app.Db = core.NewDatabase(filepath.Join(app.Config.UserDirectory, app.Config.UserDataFile))
	app.Server = core.NewServer(address)

	// read settings
	model.ReadSettingsToGlobal()

	// set other global vars with setting
	app.Theme = core.NewTheme(filepath.Join(app.Config.UserDirectory, app.Config.UserThemeDirectory),
		model.Settings["theme"].GetString())

	// init server
	action.Call(InitServer, nil)
	// init router
	action.Call(InitRoute, nil)

	// start server
	core.Start(app.Server)

	log.Info("Serv|Close|%.1fms", time.Since(t).Seconds()*1000)
}
Example #3
0
// open database file
func NewDatabase(file string) *Database {
	v, _, _ := sqlite3.Version()
	log.Info("Db|Connect|SQLite %s|%s", v, file)
	engine, err := xorm.NewEngine("sqlite3", file)
	if err != nil {
		log.Fatal("Db|Connect|Error|%s", err.Error())
	}
	engine.ShowDebug = true
	engine.ShowInfo = false
	//engine.SetLogger(nil)
	return &Database{engine}
}