Ejemplo n.º 1
0
func main() {
	setting.Initialize()
	beego.SetLogFuncCall(true)
	beego.SetViewsPath("views")

	if setting.IsProMode {
		beego.Info(setting.PostgresMigrateConnection)
		//auto migrate db
		//todo: we may want to disable this later
		//dbMigrate()
	} else {
		beego.Info("Develment mode enabled")
	}
	dbMigrate()
	beego.Info(beego.BConfig.AppName, setting.APP_VER, setting.AppUrl)
	testOnly() //todo:remove this
	//dev directory listing
	if !setting.IsProMode {
		beego.SetStaticPath("/assets", "static/dist/assets")
		beego.BConfig.WebConfig.DirectoryIndex = true
	}
	orm.RegisterDriver("postgres", orm.DRPostgres)

	orm.RegisterDataBase("default", "postgres", setting.PostgresConnection)
	services.Register()
	orm.RunCommand()
	orm.Debug = true

	controllers.RegisterControllers()

	if beego.BConfig.RunMode == "dev" {
		//	beego.Router("/test/:tmpl(mail/.*)", new(base.TestRouter))
	}
	beego.Run()
}
Ejemplo n.º 2
0
func main() {
	models.InitDB(true, true)

	beego.SetLogFuncCall(true)
	beego.AutoRender = false
	beego.Run()
}
Ejemplo n.º 3
0
Archivo: main.go Proyecto: lcbyz/Go
func main() {
	beego.SetLevel(beego.LevelInformational)
	beego.SetLogFuncCall(true)
	beego.SetLogger("file", `{"filename":"logs/test.log"}`)
	orm.Debug = true
	orm.RunSyncdb("default", false, true)
	beego.Run()
}
Ejemplo n.º 4
0
func main() {
	orm.Debug = true
	beego.SetLogFuncCall(true)            //开启日志输出
	beego.SessionOn = true                //开启Session
	orm.RunSyncdb("default", false, true) //设置创建表结构
	beego.SetStaticPath("/html", "html")  //开启html静态目录
	beego.Run()
}
Ejemplo n.º 5
0
func main() {
	beego.SetLogger("file", `{"filename":"logs/output.log"}`)
	beego.SetLogFuncCall(true)

	controllers.DIYFunc()
	beego.ErrorController(&controllers.ErrorController{})

	beego.Run()
}
Ejemplo n.º 6
0
func main() {

	//initCache()
	orm.Debug, _ = beego.AppConfig.Bool("orm_debug")
	//logFile := beego.AppConfig.String("log_file")
	beego.SetLogger("file", `{"filename":"logs/o2oapi.log"}`)
	beego.SetLogFuncCall(true)

	beego.Run()

}
Ejemplo n.º 7
0
func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	beego.SetLogFuncCall(true)
	beego.SessionOn = true
	goth.UseProviders(
		gplus.New(
			beego.AppConfig.String("CLIENT_ID"),
			beego.AppConfig.String("CLIENT_SECRET"),
			beego.AppConfig.String("CLIENT_CALLBACK"),
		),
	)
	SessionTimeout, err := beego.AppConfig.Int("SESSION_TIMEOUT")
	if err != nil {
		beego.Critical(err)
	}
	SessionRefreshInterval, err := beego.AppConfig.Int("SESSION_REFRESH_INTERVAL")
	if err != nil {
		beego.Critical(err)
	}
	goJwt.Conf = goJwt.JwtConf{
		PrivateKeyFile:         beego.AppConfig.String("PrivateKeyFile"),
		PublicKeyFile:          beego.AppConfig.String("PublicKeyFile"),
		Algorithm:              beego.AppConfig.String("Algorithm"),
		SessionSecret:          beego.AppConfig.String("SESSION_SECRET"),
		SessionName:            beego.AppConfig.String("SESSION_NAME"),
		SessionTimeout:         SessionTimeout,
		SessionRefreshInterval: SessionRefreshInterval,
	}
	goJwt.Configure()
	goJwt.Store = sessions.NewCookieStore([]byte(beego.AppConfig.String("SESSION_SECRET")))

	ldapPort, err := beego.AppConfig.Int("Ldap_port")
	if err != nil {
		beego.Critical(err)
	}
	tim.Conf = tim.LdapConf{
		Ldap_server: beego.AppConfig.String("Ldap_server"),
		Ldap_port:   uint16(ldapPort),
		Base_dn:     beego.AppConfig.String("Base_dn"),
		Ldap_user:   beego.AppConfig.String("Ldap_user"),
		Ldap_pass:   beego.AppConfig.String("Ldap_pass"),
	}

	beego.SetStaticPath("/public", "static")

	if err != nil {
		beego.Critical("Cannot connect to Redis: ", err)
		return
	}

	beego.Run()
}
Ejemplo n.º 8
0
func main() {
	beego.SessionOn = true
	beego.ErrorController(&controllers.ErrorController{})
	beego.AddFuncMap("i18n", i18n.Tr)

	beego.EnableAdmin = true // Port 8088

	beego.SetLogger("file", `{"filename":"logs/juna.log"}`)
	beego.SetLevel(beego.LevelInformational)
	beego.SetLogFuncCall(true)

	beego.AddFuncMap("news", news)
	beego.Run()
}
Ejemplo n.º 9
0
func main() {

	models.InitDb()
	beego.SessionOn = true
	beego.SetLogger("file", `{"filename":"`+common.Webconfig.LogFile+`"}`)
	beego.SetLevel(beego.LevelInformational)
	beego.SetLogFuncCall(true)
	beego.Info("begin setting router")

	beego.Router("/", &routers.HomeRouter{})
	beego.Router(`/page/:page([\d]+)`, &routers.HomeRouter{})

	beego.Router(`/article/:article([\w-]+)`, &routers.ArticleRouter{})

	beego.Router(`/tag/:tag([\S]+)/:page([\d]+)`, &routers.TagRouter{})
	beego.Router(`/tag/:tag([\S]+)`, &routers.TagRouter{})

	beego.Router(`/node/:node([\S]+)/:page([\d]+)`, &routers.NodeRouter{})
	beego.Router(`/node/:node([\S]+)`, &routers.NodeRouter{})

	beego.Router(`/category/:category([\S]+)/:page([\d]+)`, &routers.CategoryRouter{})
	beego.Router(`/category/:category([\S]+)`, &routers.CategoryRouter{})

	beego.Router("/subscribe", &routers.SubscribeRouter{})
	beego.Router(`/subscribe/:uid([\S]+)`, &routers.SubscribeRouter{})
	beego.Router(`/desubscribe/:uid([\S]+)`, &routers.SubscribeRouter{})

	beego.Router("/root", &root.RootMainRouter{})

	beego.Router("/root/category", &root.RootCategoryRouter{})

	beego.Router("/root/node", &root.RootNodeRouter{})

	beego.Router("/root/tag", &root.RootTagRouter{})

	beego.Router(`/root/article`, &root.RootArticleRouter{})
	//beego.Router(`/root/article/:opt([a-z]+)`, &root.RootArticleRouter{})
	beego.Router(`/root/article/:page([\d]+)`, &root.RootArticleRouter{})

	beego.Router("/root/upload", &root.RootUploadRouter{})

	beego.Router("/root/login", &root.LoginRouter{})
	beego.Router("/root/loginout", &root.LoginOutRouter{})

	beego.Router(`/prompt/:code([\w]+)`, &routers.PromptRouter{})

	beego.Info("starting server")
	beego.Run()
}
Ejemplo n.º 10
0
func init() {
	beego.AppConfigPath = "conf/app.conf"
	beego.SetStaticPath("/js", "public/js")
	beego.SetStaticPath("/img", "public/img")
	beego.SetStaticPath("/favicon.ico", "public/img/favicon.ico")
	beego.SetStaticPath("/css", "public/css")
	beego.SetStaticPath("/html", "tpl")
	beego.SetStaticPath("/admin/js", "public/admin/js")
	beego.SetStaticPath("/admin/img", "public/admin/img")
	beego.SetStaticPath("/admin/css", "public/admin/css")
	beego.SetStaticPath("/admin/assets", "public/admin")
	beego.SetLevel(beego.LevelDebug)
	beego.SetLogFuncCall(true)
	beego.BeeLogger.SetLogFuncCallDepth(4)
	bm, _ = cache.NewCache("memory", `{"interval":60}`)
}
Ejemplo n.º 11
0
func init() {
	showNumberLine, _ := beego.AppConfig.Bool("logger.numberLine")
	levelString := beego.AppConfig.String("logger.level")
	logModels := beego.AppConfig.Strings("logger.logger")
	for _, logModel := range logModels {
		if logModel == "console" {
			beego.SetLogger("console", "")
		}
		if logModel == "file" {
			filename := beego.AppConfig.String("logger.filename")
			config := fmt.Sprintf(`{"filename":"%s","maxdays":30}`, filename)
			beego.SetLogger("file", config)
		}
	}
	if showNumberLine {
		beego.SetLogFuncCall(showNumberLine)
	}
	level, _ := Levelify(levelString)
	beego.SetLevel(level)
}
Ejemplo n.º 12
0
// We have to call a initialize function manully
// because we use `bee bale` to pack static resources
// and we cannot make sure that which init() execute first.
func initialize() {
	setting.LoadConfig()

	//set logger
	if setting.IsProMode {
		beego.SetLogger("file", `{"filename":"logs/prod.log"}`)
		beego.SetLevel(beego.LevelInformational)
		beego.BeeLogger.DelLogger("console")
	} else {
		beego.SetLogger("file", `{"filename":"logs/dev.log"}`)
		beego.SetLevel(beego.LevelDebug)
		beego.BeeLogger.SetLogger("console", "")
	}
	beego.SetLogFuncCall(true)
	setting.SocialAuth = social.NewSocial("/login/", auth.SocialAuther)
	setting.SocialAuth.ConnectSuccessURL = "/settings/profile"
	setting.SocialAuth.ConnectFailedURL = "/settings/profile"
	setting.SocialAuth.ConnectRegisterURL = "/register/connect"
	setting.SocialAuth.LoginURL = "/login"

	//Qiniu
	ACCESS_KEY = setting.QiniuAccessKey
	SECRET_KEY = setting.QiniuSecurityKey
}
Ejemplo n.º 13
0
func main() {

	m.Connect()
	beego.ViewsPath = "views"
	beego.TemplateLeft = "<<<"
	beego.TemplateRight = ">>>"

	beego.AddTemplateExt("html")
	beego.SetStaticPath("/public", "public")

	beego.SetLogger("file", `{"filename":"logs/finprocess.log"}`)
	beego.SetLogFuncCall(true)

	logLevel, _ := beego.AppConfig.Int("log_level")
	beego.SetLevel(logLevel)

	//minutes for duration
	duration, _ := beego.AppConfig.Int("task_duration")

	go tasks.DailyTaskInit(duration) //启动task

	beego.Run()

}
Ejemplo n.º 14
0
func main() {
	beego.SetLogFuncCall(true)

	initialize()

	beego.Info("AppPath:", beego.AppPath)

	if setting.IsProMode {
		beego.Info("Product mode enabled")
	} else {
		beego.Info("Develment mode enabled")
	}
	beego.Info(beego.BConfig.AppName, setting.APP_VER, setting.AppUrl)

	if !setting.IsProMode {
		beego.SetStaticPath("/static_source", "static_source")
		beego.BConfig.WebConfig.DirectoryIndex = true
	}

	// Add Filters
	beego.InsertFilter("/img/*", beego.BeforeRouter, attachment.ImageFilter)

	beego.InsertFilter("/captcha/*", beego.BeforeRouter, setting.Captcha.Handler)

	// Register routers.
	posts := new(post.PostListRouter)
	beego.Router("/", posts, "get:Home")
	beego.Router("/:slug(recent|best|cold|favs|follow)", posts, "get:Navs")
	beego.Router("/category/:slug", posts, "get:Category")
	beego.Router("/topic/:slug", posts, "get:Topic;post:TopicSubmit")

	postR := new(post.PostRouter)
	beego.Router("/new", postR, "get:New;post:NewSubmit")
	beego.Router("/post/:post([0-9]+)", postR, "get:Single;post:SingleSubmit")
	beego.Router("/post/:post([0-9]+)/edit", postR, "get:Edit;post:EditSubmit")

	if setting.NativeSearch || setting.SphinxEnabled {
		searchR := new(post.SearchRouter)
		beego.Router("/search", searchR, "get:Get")
	}

	user := new(auth.UserRouter)
	beego.Router("/user/:username/comments", user, "get:Comments")
	beego.Router("/user/:username/posts", user, "get:Posts")
	beego.Router("/user/:username/following", user, "get:Following")
	beego.Router("/user/:username/followers", user, "get:Followers")
	beego.Router("/user/:username/favs", user, "get:Favs")
	beego.Router("/user/:username", user, "get:Home")

	login := new(auth.LoginRouter)
	beego.Router("/login", login, "get:Get;post:Login")
	beego.Router("/logout", login, "get:Logout")

	beego.InsertFilter("/login/*/access", beego.BeforeRouter, auth.OAuthAccess)
	beego.InsertFilter("/login/*", beego.BeforeRouter, auth.OAuthRedirect)

	socialR := new(auth.SocialAuthRouter)
	beego.Router("/register/connect", socialR, "get:Connect;post:ConnectPost")

	register := new(auth.RegisterRouter)
	beego.Router("/register", register, "get:Get;post:Register")
	beego.Router("/active/success", register, "get:ActiveSuccess")
	beego.Router("/active/:code([0-9a-zA-Z]+)", register, "get:Active")

	settings := new(auth.SettingsRouter)
	beego.Router("/settings/profile", settings, "get:Profile;post:ProfileSave")

	forgot := new(auth.ForgotRouter)
	beego.Router("/forgot", forgot)
	beego.Router("/reset/:code([0-9a-zA-Z]+)", forgot, "get:Reset;post:ResetPost")

	upload := new(attachment.UploadRouter)
	beego.Router("/upload", upload, "post:Post")

	apiR := new(api.ApiRouter)
	beego.Router("/api/user", apiR, "post:Users")
	beego.Router("/api/md", apiR, "post:Markdown")

	adminDashboard := new(admin.AdminDashboardRouter)
	beego.Router("/admin", adminDashboard)

	adminR := new(admin.AdminRouter)
	beego.Router("/admin/model/get", adminR, "post:ModelGet")
	beego.Router("/admin/model/select", adminR, "post:ModelSelect")

	routes := map[string]beego.ControllerInterface{
		"user":     new(admin.UserAdminRouter),
		"post":     new(admin.PostAdminRouter),
		"comment":  new(admin.CommentAdminRouter),
		"topic":    new(admin.TopicAdminRouter),
		"category": new(admin.CategoryAdminRouter),
		"article":  new(admin.ArticleAdminRouter),
	}
	for name, router := range routes {
		beego.Router(fmt.Sprintf("/admin/:model(%s)", name), router, "get:List")
		beego.Router(fmt.Sprintf("/admin/:model(%s)/:id(new)", name), router, "get:Create;post:Save")
		beego.Router(fmt.Sprintf("/admin/:model(%s)/:id([0-9]+)", name), router, "get:Edit;post:Update")
		beego.Router(fmt.Sprintf("/admin/:model(%s)/:id([0-9]+)/:action(delete)", name), router, "get:Confirm;post:Delete")
	}

	// "robot.txt"
	beego.Router("/robot.txt", &base.RobotRouter{})

	articleR := new(article.ArticleRouter)
	beego.Router("/:slug", articleR, "get:Show")

	if beego.BConfig.RunMode == "dev" {
		beego.Router("/test/:tmpl(mail/.*)", new(base.TestRouter))
	}

	// For all unknown pages.
	beego.Run()
}