Ejemplo n.º 1
0
// new site
func NewSite(ctx *cli.Context) {
	config := model.NewConfig()

	// encode config
	if err := model.WriteConfig(config, vars.CONFIG_FILE); err != nil {
		log.Error("NewSite | %s", err.Error())
		return
	}

	log.Info("NewSite | %-8s | %s", "Init", vars.CONFIG_FILE)
	log.Info("NewSite | %-8s | %s", "Version", config.Version)
	log.Info("NewSite | %-8s | %s:%s", "Server", config.Server.Host, config.Server.Port)
}
Ejemplo n.º 2
0
// upgrade action
func UpgradeAction(cfg *model.Config) {
	t := time.Now()
	log.Debug("Upgrade | %-8s | %s(%s) -> %s(%s)", "Upgrade", cfg.Version, cfg.Date, vars.VERSION, vars.VERSION_DATE)

	opt := &PrepareOption{true, true, false}
	pre, err := Prepare(opt)
	if err != nil {
		log.Error("Upgrade | %-8s | %s", "Prepare", err.Error())
		return
	}
	log.Info("Upgrade | %-8s | %s", "Prepare", opt.String())

	oldVersion, _ := strconv.Atoi(pre.Config.Date)
	scriptIndex := []int{}
	for vr, _ := range upg.Script {
		if vr > oldVersion {
			scriptIndex = append(scriptIndex, vr)
		}
	}
	sort.Sort(sort.IntSlice(scriptIndex))

	for _, cv := range scriptIndex {
		log.Debug("Upgrade | %-8s | %d ", "Process", cv)
		if err := upg.Script[cv](); err != nil {
			log.Error("Upgrade | %-8s | %s", "Process", err.Error())
			return
		}
	}

	pre.Config.Version = vars.VERSION
	pre.Config.Date = vars.VERSION_DATE
	if err := model.WriteConfig(pre.Config, vars.CONFIG_FILE); err != nil {
		log.Error("Upgrade | %-8s | SyncFail", "Config")
		return
	}

	log.Info("Upgrade | %-8s | Sync | %s", "Config", vars.CONFIG_FILE)
	log.Info("Upgrade | %-8s | %.1fms", "Done", time.Since(t).Seconds()*1000)
}