// Init starts Fxh.Go application preparation. // Load models and plugins, update views. func Init() { // init storage model.Init(VERSION) // load all data model.All() // init plugin plugin.Init() // update plugin handlers plugin.Update(App) App.View().FuncMap["DateInt64"] = utils.DateInt64 App.View().FuncMap["DateString"] = utils.DateString App.View().FuncMap["DateTime"] = utils.DateTime App.View().FuncMap["Now"] = utils.Now App.View().FuncMap["Html2str"] = utils.Html2str App.View().FuncMap["FileSize"] = utils.FileSize App.View().FuncMap["Setting"] = model.GetSetting App.View().FuncMap["Navigator"] = model.GetNavigators App.View().FuncMap["Md2html"] = utils.Markdown2HtmlTemplate App.View().IsCache = (model.GetSetting("theme_cache") == "true") println("app version @ " + strconv.Itoa(model.GetVersion().Version)) }
func CheckUpgrade(v int, print bool) bool { model.Init(v) appV := model.GetVersion() b := v > appV.Version if b && print { println("app version @ " + strconv.Itoa(v) + " is ahead of current version @ " + strconv.Itoa(appV.Version) + " , please run 'GoBlog upgrade'") } return b }
func DoUpgrade(v int, app *GoInk.App) { if !CheckUpgrade(v, false) { println("app version @", v, "is updated") return } oldVersion := model.GetVersion().Version scriptIndex := []int{} for vr, _ := range upgradeScript { if vr <= v && vr > oldVersion { scriptIndex = append(scriptIndex, vr) } } sort.Sort(sort.IntSlice(scriptIndex)) for _, cv := range scriptIndex { upgradeScript[cv](app) println("upgrade @", cv, "success") } model.GetVersion().Version = v model.SyncVersion() println("app has upgraded to version @", v, "successfully, restart and keep enjoy !!") }