func init() { // config revel.OnAppStart(LoadConfig) // gorp revel.OnAppStart(InitDB) // service account revel.InterceptMethod((*AlphaWingController).InitGoogleService, revel.BEFORE) // auth revel.InterceptMethod((*AlphaWingController).InitOAuthConfig, revel.BEFORE) revel.InterceptMethod((*AlphaWingController).SetLoginInfo, revel.BEFORE) revel.InterceptMethod((*AuthController).CheckLogin, revel.BEFORE) // validate app revel.InterceptMethod((*AppControllerWithValidation).CheckNotFound, revel.BEFORE) revel.InterceptMethod((*AppControllerWithValidation).CheckForbidden, revel.BEFORE) // validate bundle revel.InterceptMethod((*BundleControllerWithValidation).CheckNotFound, revel.BEFORE) revel.InterceptMethod((*BundleControllerWithValidation).CheckForbidden, revel.BEFORE) revel.InterceptMethod((*LimitedTimeController).CheckNotFound, revel.BEFORE) // validate limited time token revel.InterceptMethod((*LimitedTimeController).CheckValidLimitedTimeToken, revel.BEFORE) // document revel.OnAppStart(GenerateApiDocument) // args revel.InterceptMethod((*AlphaWingController).InitRenderArgs, revel.AFTER) }
// in your app initialization.. func init() { revel.TemplateFuncs["appendjs"] = func(renderArgs map[string]interface{}, key string, value interface{}) template.HTML { s := value.(string) js_code := template.JS(s) if renderArgs[key] == nil { renderArgs[key] = []interface{}{js_code} } else { renderArgs[key] = append(renderArgs[key].([]interface{}), js_code) } return template.HTML("") } // Filters is the default set of global filters. revel.Filters = []revel.Filter{ revel.PanicFilter, // Recover from panics and display an error page instead. revel.RouterFilter, // Use the routing table to select the right Action revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. revel.ParamsFilter, // Parse parameters into Controller.Params. revel.SessionFilter, // Restore and write the session cookie. revel.FlashFilter, // Restore and write the flash cookie. csrf.CSRFFilter, // CSRF prevention. revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. revel.I18nFilter, // Resolve the requested language HeaderFilter, // Add some security based headers revel.InterceptorFilter, // Run interceptors around the action. revel.ActionInvoker, // Invoke the action. } revel.OnAppStart(func() { appPath := revel.BasePath for _, AC := range compilers { path := filepath.Join(appPath, AC.Path) revel.INFO.Printf("Listening: %q\n", path) revel.MainWatcher.Listen(AC, path) } }) // add interceptors revel.InterceptMethod((*ctrl.DbController).Begin, revel.BEFORE) revel.InterceptMethod(ctrl.App.RenderArgsFill, revel.BEFORE) revel.InterceptMethod(ctrl.App.RecordPageRequest, revel.BEFORE) revel.InterceptMethod(ctrl.User.CheckLoggedIn, revel.BEFORE) revel.InterceptMethod(ctrl.Admin.CheckLoggedIn, revel.BEFORE) revel.InterceptMethod((*ctrl.DbController).Commit, revel.AFTER) revel.InterceptMethod((*ctrl.DbController).Rollback, revel.FINALLY) revel.OnAppStart(func() { ctrl.InitDB() if revel.RunMode == "dev" { ctrl.SetupDevDB() } if revel.RunMode == "prod" { ctrl.SetupTables() } }) }
func init() { // interceptor // revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Index{}) // Index.Note自己校验 revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Notebook{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Note{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Share{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &User{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &File{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Blog{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &NoteContentHistory{}) // service userService = &service.UserService{} noteService = &service.NoteService{} trashService = &service.TrashService{} notebookService = &service.NotebookService{} noteContentHistoryService = &service.NoteContentHistoryService{} authService = &service.AuthService{} shareService = &service.ShareService{} blogService = &service.BlogService{} tagService = &service.TagService{} pwdService = &service.PwdService{} tokenService = &service.TokenService{} suggestionService = &service.SuggestionService{} revel.OnAppStart(func() { leanoteUserId, _ = revel.Config.String("adminUsername") siteUrl, _ = revel.Config.String("site.url") openRegister, _ = revel.Config.Bool("register.open") }) }
func init() { revel.OnAppStart(func() { /* 不用配置的, 因为最终通过命令可以改, 而且有的使用nginx代理 port = strconv.Itoa(revel.HttpPort) if port != "80" { port = ":" + port } else { port = ""; } */ siteUrl, _ := revel.Config.String("site.url") // 已包含:9000, http, 去掉成 leanote.com if strings.HasPrefix(siteUrl, "http://") { defaultDomain = siteUrl[len("http://"):] } else if strings.HasPrefix(siteUrl, "https://") { defaultDomain = siteUrl[len("https://"):] schema = "https://" } // port localhost:9000 ports := strings.Split(defaultDomain, ":") if len(ports) == 2 { port = ports[1] } if port == "80" { port = "" } else { port = ":" + port } }) }
func init() { revel.Filters = []revel.Filter{ revel.RouterFilter, revel.ParamsFilter, revel.ActionInvoker, } revel.OnAppStart(func() { var err error db.Init() db.Db.SetMaxIdleConns(MaxConnectionCount) dbm.InitJet() dbm.Jet.SetMaxIdleConns(MaxConnectionCount) dbm.InitQbs(MaxConnectionCount) if worldStatement, err = db.Db.Prepare(WorldSelect); err != nil { revel.ERROR.Fatalln(err) } if fortuneStatement, err = db.Db.Prepare(FortuneSelect); err != nil { revel.ERROR.Fatalln(err) } if updateStatement, err = db.Db.Prepare(WorldUpdate); err != nil { revel.ERROR.Fatalln(err) } }) }
func init() { revel.OnAppStart(InitDB) revel.InterceptMethod((*GorpController).Begin, revel.BEFORE) revel.InterceptMethod((*GorpController).Commit, revel.AFTER) revel.InterceptMethod((*GorpController).Rollback, revel.FINALLY) }
func init() { // Filters is the default set of global filters. revel.Filters = []revel.Filter{ revel.PanicFilter, // Recover from panics and display an error page instead. revel.RouterFilter, // Use the routing table to select the right Action revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. revel.ParamsFilter, // Parse parameters into Controller.Params. revel.SessionFilter, // Restore and write the session cookie. revel.FlashFilter, // Restore and write the flash cookie. revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. revel.I18nFilter, // Resolve the requested language HeaderFilter, // Add some security based headers revel.InterceptorFilter, // Run interceptors around the action. revel.CompressFilter, // Compress the result. revel.ActionInvoker, // Invoke the action. } // register startup functions with OnAppStart // Can also be called per init file in each package for package specific init function // ( order dependent ) // revel.OnAppStart(InitDB) // revel.OnAppStart(FillCache) revel.OnAppStart(func() { var found bool Driver, found = revel.Config.String("db.driver") if !found { panic("db.driver is not defined in the config section.") } fmt.Println("Using db.driver value from config: %s", Driver) }) }
func init() { revel.OnAppStart(func() { go common.UnzipSwaggerAssets() // build IndexArgs for rendering index template // collect all of the swagger-endpoints then build the spec routes := make([]*revel.Route, 0) for _, route := range revel.MainRouter.Routes { if strings.ToLower(route.Action) == "swaggify.spec" { routes = append(routes, route) } } for _, route := range routes { // TODO test what cases cause bounds panic // Don't duplicate building API specs if _, exists := APIs[route.FixedParams[0]]; exists { continue } APIs[route.FixedParams[0]] = newSpec(route.FixedParams[0]) fmt.Println(APIs[route.FixedParams[0]]) } }) }
func init() { // Filters is the default set of global filters. revel.Filters = []revel.Filter{ revel.PanicFilter, // Recover from panics and display an error page instead. revel.I18nFilter, // Resolve the requested language revel.RouterFilter, // Use the routing table to select the right Action revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. revel.ParamsFilter, // Parse parameters into Controller.Params. revel.SessionFilter, // Restore and write the session cookie. csrf.CSRFFilter, revel.FlashFilter, // Restore and write the flash cookie. revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. HeaderFilter, // Add xnsome security based headers revel.InterceptorFilter, // Run interceptors around the action. revel.CompressFilter, // Compress the result. revel.ActionInvoker, // Invoke the action. } revel.OnAppStart(models.InitDB) revel.InterceptFunc(setNickname, revel.BEFORE, &pages.ShopPage{}) revel.InterceptFunc(setNickname, revel.BEFORE, &pages.Authentication{}) revel.InterceptFunc(setNickname, revel.BEFORE, &pages.Admin{}) revel.InterceptFunc(redirectAuthenticationPageForAdmin, revel.BEFORE, &pages.Admin{}) // register startup functions with OnAppStart // ( order dependent ) // revel.OnAppStart(InitDB) // revel.OnAppStart(FillCache) }
func init() { revel.InterceptMethod((*XormController).Attach, revel.BEFORE) revel.InterceptMethod((*XormController).Commit, revel.AFTER) revel.InterceptMethod((*XormController).Detach, revel.FINALLY) revel.InterceptMethod((*XormSessionController).Attach, revel.BEFORE) revel.OnAppStart(Init) }
func init() { runtime.GOMAXPROCS(runtime.NumCPU()) revel.TemplateFuncs["formatTime"] = func(t time.Time) template.HTML { return template.HTML(t.Format(storage.TimePattern)) } revel.TemplateFuncs["join"] = func(ss []string) template.HTML { return template.HTML(strings.Join(ss, " ")) } revel.TemplateFuncs["highlight"] = func(search string, input template.HTML) template.HTML { inputS := string(input) index := strings.Index(inputS, search) if index == -1 { return input } r := inputS[:index] + "<span class=highlight>" + search + "</span>" + inputS[index+len(search):] return template.HTML(r) } // forbid sequent handlers for go playground playFilter := func(c *revel.Controller, fc []revel.Filter) { c.Result = PlayResult{} return } revel.FilterAction(Application.Play). Insert(playFilter, revel.BEFORE, revel.ParamsFilter) //register posts plugin revel.OnAppStart(onStart) }
// in your app initialization.. func init() { // Filters is the default set of global filters. revel.Filters = []revel.Filter{ revel.PanicFilter, // Recover from panics and display an error page instead. revel.RouterFilter, // Use the routing table to select the right Action revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. revel.ParamsFilter, // Parse parameters into Controller.Params. revel.SessionFilter, // Restore and write the session cookie. revel.FlashFilter, // Restore and write the flash cookie. csrf.CSRFFilter, // CSRF prevention. revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. revel.I18nFilter, // Resolve the requested language HeaderFilter, // Add some security based headers revel.InterceptorFilter, // Run interceptors around the action. revel.ActionInvoker, // Invoke the action. } revel.OnAppStart(func() { appPath := revel.BasePath for _, AC := range compilers { path := filepath.Join(appPath, AC.Path) revel.INFO.Printf("Listening: %q\n", path) revel.MainWatcher.Listen(AC, path) } }) }
func init() { // Filters is the default set of global filters. revel.Filters = []revel.Filter{ revel.PanicFilter, // Recover from panics and display an error page instead. revel.RouterFilter, // Use the routing table to select the right Action revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. revel.ParamsFilter, // Parse parameters into Controller.Params. revel.SessionFilter, // Restore and write the session cookie. revel.FlashFilter, // Restore and write the flash cookie. revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. revel.I18nFilter, // Resolve the requested language HeaderFilter, // Add some security based headers revel.InterceptorFilter, // Run interceptors around the action. revel.CompressFilter, // Compress the result. revel.ActionInvoker, // Invoke the action. } var card models.Card revel.TypeBinders[reflect.TypeOf(card)] = binders.CardBinder // register startup functions with OnAppStart // ( order dependent ) revel.OnAppStart(database.InitDB) // revel.OnAppStart(FillCache) }
func init() { // Filters is the default set of global filters. revel.Filters = []revel.Filter{ revel.PanicFilter, // Recover from panics and display an error page instead. revel.RouterFilter, // Use the routing table to select the right Action revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. revel.ParamsFilter, // Parse parameters into Controller.Params. revel.SessionFilter, // Restore and write the session cookie. revel.FlashFilter, // Restore and write the flash cookie. revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. revel.I18nFilter, // Resolve the requested language HeaderFilter, // Add some security based headers revel.InterceptorFilter, // Run interceptors around the action. revel.CompressFilter, // Compress the result. ActionInvoker, // Invoke the action. } // revel.TimeFormats = append(revel.TimeFormats, "2006/01/01") // ( order dependent ) // revel.OnAppStart(InitDB) // revel.OnAppStart(FillCache) revel.OnAppStart(func() { models.InitDB() core.Init() }) }
func init() { revel.OnAppStart(func() { assetsFixedParams = map[string][]string{ "prefix": []string{common.SwaggerAssetsDir}, } }) }
func init() { revel.OnAppStart(Initialize) revel.InterceptMethod((*DatabaseController).Begin, revel.BEFORE) //revel.InterceptMethod((*Profile).Index, revel.BEFORE) revel.InterceptMethod((*DatabaseController).Commit, revel.AFTER) revel.InterceptMethod((*DatabaseController).Rollback, revel.FINALLY) }
func init() { // Filters is the default set of global filters. revel.Filters = []revel.Filter{ revel.PanicFilter, // Recover from panics and display an error page instead. revel.RouterFilter, // Use the routing table to select the right Action revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. revel.ParamsFilter, // Parse parameters into Controller.Params. revel.SessionFilter, // Restore and write the session cookie. revel.FlashFilter, // Restore and write the flash cookie. revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. revel.I18nFilter, // Resolve the requested language HeaderFilter, // Add some security based headers revel.InterceptorFilter, // Run interceptors around the action. revel.CompressFilter, // Compress the result. revel.ActionInvoker, // Invoke the action. } // register startup functions with OnAppStart // ( order dependent ) revel.OnAppStart(controllers.InitDB) revel.InterceptMethod((*controllers.GormController).Begin, revel.BEFORE) revel.InterceptMethod((*controllers.GormController).Commit, revel.AFTER) revel.InterceptMethod((*controllers.GormController).Rollback, revel.FINALLY) // revel.OnAppStart(FillCache) }
// HeaderFilter initialize Revel App func init() { // Filters is the default set of global filters. revel.Filters = []revel.Filter{ revel.PanicFilter, // Recover from panics and display an error page instead. revel.RouterFilter, // Use the routing table to select the right Action revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. revel.ParamsFilter, // Parse parameters into Controller.Params. revel.SessionFilter, // Restore and write the session cookie. revel.FlashFilter, // Restore and write the flash cookie. revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. revel.I18nFilter, // Resolve the requested language HeaderFilter, // Add some security based headers revel.InterceptorFilter, // Run interceptors around the action. revel.CompressFilter, // Compress the result. revel.ActionInvoker, // Invoke the action. } // register startup functions with OnAppStart // ( order dependent ) revel.OnAppStart(func() { dbm := InitDB() dbm.AutoMigrate(&usermodules.User{}, &usermodules.Profile{}, &models.SpendingType{}, &models.Spending{}) }) // revel.OnAppStart(FillCache) }
func init() { // Filters is the default set of global filters. revel.Filters = []revel.Filter{ revel.PanicFilter, // Recover from panics and display an error page instead. revel.RouterFilter, // Use the routing table to select the right Action revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. revel.ParamsFilter, // Parse parameters into Controller.Params. revel.SessionFilter, // Restore and write the session cookie. revel.FlashFilter, // Restore and write the flash cookie. revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. revel.I18nFilter, // Resolve the requested language HeaderFilter, // Add some security based headers revel.InterceptorFilter, // Run interceptors around the action. revel.CompressFilter, // Compress the result. revel.ActionInvoker, // Invoke the action. } // register startup functions with OnAppStart // ( order dependent ) // revel.OnAppStart(InitDB) // revel.OnAppStart(FillCache) // Create a link back to node-webkit using the environment variable // populated by golang-nw's node-webkit code revel.OnAppStart(func() { open.Run("http://localhost:9000") }) }
func init() { revel.OnAppStart(func() { // set security key to app.secret sec, found := revel.Config.String("app.secret") if !found { revel.ERROR.Fatal("No app.secret setting was found in app.conf.") } SecurityKey = sec // setup providers allowed in app.config's auth.providersallowed setting configItm, found := revel.Config.String("auth.providersallowed") if found { revel.INFO.Printf("Setting up the following providers: %s", configItm) configResults := strings.Split(configItm, ",") for idx := 0; idx < len(configResults); idx++ { providerItm := strings.Trim(strings.ToLower(configResults[idx]), " ") // set the AuthProvider for each type requested switch providerItm { case "facebook": AllowedProviderGenerators["facebook"] = NewFacebookAuthProvider case "google": AllowedProviderGenerators["google"] = NewGoogleAuthProvider case "linkedin": AllowedProviderGenerators["linkedin"] = NewLinkedinAuthProvider case "twitter": AllowedProviderGenerators["twitter"] = NewTwitterAuthProvider case "github": AllowedProviderGenerators["github"] = NewGithubAuthProvider default: revel.WARN.Printf("Provider <%s> is not known. Skipped.", providerItm) } // pull AuthConfig settings from app.conf and validate it ac, err := generateAuthConfigFromAppConfig(providerItm) if err != nil { revel.ERROR.Fatal(err) } else { validator := AuthConfigValidator.Validate(ac) if validator.HasErrors() { revel.WARN.Printf("Configuration data for %s does not validate. Added anyways, but please confirm settings.", providerItm) } else { revel.INFO.Printf("Configured %s for authentication.", providerItm) } AppAuthConfigs[providerItm] = ac } } } else { revel.ERROR.Fatal("No auth.providersallowed setting was found in app.conf.") } }) }
func init() { revel.OnAppStart(InitDB) revel.InterceptMethod((*GorpController).Begin, revel.BEFORE) revel.InterceptMethod(Application.authorize, revel.BEFORE) revel.InterceptMethod(Application.setLoginUrl, revel.BEFORE) revel.InterceptMethod((*GorpController).Commit, revel.AFTER) revel.InterceptMethod((*GorpController).Rollback, revel.FINALLY) }
func init() { revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberIndex{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberUser{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberBlog{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberGroup{}) revel.OnAppStart(func() { }) }
func init() { revel.OnAppStart(InitDB) revel.InterceptMethod((*GorpController).Begin, revel.BEFORE) revel.InterceptMethod(Application.AddUser, revel.BEFORE) revel.InterceptMethod(Hotels.checkUser, revel.BEFORE) revel.InterceptMethod((*GorpController).Commit, revel.AFTER) revel.InterceptMethod((*GorpController).Rollback, revel.FINALLY) }
func init() { revel.OnAppStart(Init) revel.InterceptMethod((*Application).checkUser, revel.BEFORE) revel.TemplateFuncs["eqis"] = func(i int64, s string) bool { return strconv.FormatInt(i, 10) == s } }
func init() { revel.OnAppStart(InitDB) revel.InterceptMethod((*GorpController).Begin, revel.BEFORE) revel.InterceptMethod(Application.SetAccount, revel.BEFORE) revel.InterceptMethod(Dashboard.checkAccount, revel.BEFORE) revel.InterceptMethod((*GorpController).Commit, revel.AFTER) revel.InterceptMethod((*GorpController).Rollback, revel.FINALLY) }
func init() { revel.OnAppStart(InitDB) revel.InterceptMethod((*XOrmController).Begin, revel.BEFORE) revel.InterceptMethod((*XOrmTnController).Begin, revel.BEFORE) revel.InterceptMethod((*XOrmTnController).Commit, revel.AFTER) revel.InterceptMethod((*XOrmTnController).Rollback, revel.PANIC) }
func init() { revel.OnAppStart(func() { ServersMap, ServersLastError = models.LoadServers() if ServersLastError != nil { revel.ERROR.Print(ServersLastError) } }) }
func init() { revel.OnAppStart(InitDB) revel.InterceptMethod((*GorpController).Begin, revel.BEFORE) revel.InterceptMethod(Account.AddAppName, revel.BEFORE) revel.InterceptMethod(Account.AddRenderMode, revel.BEFORE) revel.InterceptMethod(Account.AddUser, revel.BEFORE) revel.InterceptMethod((*GorpController).Commit, revel.AFTER) revel.InterceptMethod((*GorpController).Rollback, revel.FINALLY) }
func init() { revel.OnAppStart(func() { jobs.Schedule("0 */5 * ? * ?", MyJob{Name: "job1"}) jobs.Schedule("cron.every_1h", MyJob{Name: "job2"}) jobs.Schedule("cron.every_10m", MyJob{Name: "job3"}) jobs.Schedule("@every 1m", jobs.Func(reminder)) jobs.Now(MyJob{Name: "job Now"}) }) }
func init() { Joblist = make(map[int]*models.Job) revel.OnAppStart(func() { jobs.Now(PopulateJobs{}) jobs.Schedule("@every 24h", PopulateJobs{}) }) }