Пример #1
0
func InitDbDefault(_ interface{}) *action.Result {
	// init administrator user
	user := model.NewDefaultUser()
	if err := model.SaveUser(user); err != nil {
		return action.ErrorResult(err)
	}

	// init welcome article
	article := model.NewDefaultArticle(user.Id)
	if err := model.SaveArticle(article); err != nil {
		return action.ErrorResult(err)
	}

	// init first comment
	comment := model.NewDefaultComment(article.Id)
	if err := model.SaveComment(comment); err != nil {
		return action.ErrorResult(err)
	}

	// init default settings
	settings := model.NewDefaultSetting(user.Id)
	if err := model.SaveSettings(settings); err != nil {
		return action.ErrorResult(err)
	}

	return action.OkResult(nil)
}
Пример #2
0
// init server,
// set static files, theme and middleware
func InitServer(_ interface{}) *action.Result {

	// set static directory
	app.Server.Use(tango.Static(tango.StaticOptions{
		RootPath: filepath.Join(app.Config.UserDirectory, app.Config.UserThemeDirectory),
		Prefix:   "/theme",
	}))
	app.Server.Use(tango.Static(tango.StaticOptions{
		RootPath: filepath.Join(app.Config.UserDirectory, app.Config.UserUploadDirectory),
		Prefix:   "/upload",
	}))

	// set theme directory
	app.Server.Use(renders.New(renders.Options{
		Reload:     true,
		Directory:  filepath.Join(app.Config.UserDirectory, app.Config.UserThemeDirectory),
		Extensions: []string{".tmpl"},
	}))

	// binding middleware
	app.Server.Use(binding.Bind())
	app.Server.Use(base.AuthHandler())

	return action.OkResult(nil)
}
Пример #3
0
func InitDbSchema(_ interface{}) *action.Result {
	app.Db.Sync2(new(model.User),
		new(model.Token),
		new(model.Article),
		new(model.Tag),
		new(model.Comment),
		new(model.Setting))
	return action.OkResult(nil)
}
Пример #4
0
// init router,
// set route rules
func InitRoute(_ interface{}) *action.Result {
	// admin routes
	adminGroup := tango.NewGroup()
	adminGroup.Any("/login", new(admin.Login))
	adminGroup.Get("/logout", new(admin.Logout))
	adminGroup.Any("/profile", new(admin.Profile))
	adminGroup.Post("/password", new(admin.Password))
	adminGroup.Any("/article/new", new(admin.Write))
	adminGroup.Get("/", new(admin.Admin))

	app.Server.Group("/admin", adminGroup)
	return action.OkResult(nil)
}