func (srv *httpServer) setupMiddleware(m *martini.ClassicMartini) { m.Use(render.Renderer(render.Options{ Directory: "templates", Layout: "layout", })) m.Use(CORSAllowAny()) }
//InitSession - initializes authentication middleware for controllers func InitSession(m *martini.ClassicMartini, rc redisCreds) { m.Use(render.Renderer()) if rediStore, err := sessions.NewRediStore(10, "tcp", rc.Uri(), rc.Pass(), []byte(sessionSecret)); err == nil { m.Use(sessions.Sessions(sessionName, rediStore)) } }
func Mount(m *martini.ClassicMartini, concurrent int) { fmt.Println("concurrent @v:", concurrent) m.Use(utee.MidConcurrent(concurrent)) m.Use(render.Renderer()) m.Use(utee.MidTextDefault) // //map request web utilities m.Use(func(w http.ResponseWriter, c martini.Context) { web := &utee.Web{W: w} c.Map(web) }) m.Use(func(c martini.Context){ var msgs []string for i:=0;i<100000;i++ { msgs = append(msgs,fmt.Sprint("testMsg",i)) } c.Map(msgs) }) m.Group("/hello", func(r martini.Router) { r.Post("/world", test) r.Get("/world", test) }) http.Handle("/", m) // http.HandleFunc("/test/a", testhandler) }
//InitRoutes - initialize the mappings for controllers against valid routes func InitRoutes(m *martini.ClassicMartini, redisConn Doer, mongoConn pezdispenser.MongoCollectionGetter, authClient AuthRequestCreator) { setOauthConfig() keyGen := NewKeyGen(redisConn, &GUIDMake{}) m.Use(render.Renderer()) m.Use(martini.Static(StaticPath)) m.Use(oauth2.Google(OauthConfig)) authKey := NewAuthKeyV1(keyGen) m.Get("/info", authKey.Get()) m.Get(ValidKeyCheck, NewValidateV1(keyGen).Get()) m.Get("/me", oauth2.LoginRequired, DomainCheck, NewMeController().Get()) m.Get("/", oauth2.LoginRequired, DomainCheck, func(params martini.Params, log *log.Logger, r render.Render, tokens oauth2.Tokens) { userInfo := GetUserInfo(tokens) r.HTML(SuccessStatus, "index", userInfo) }) m.Post("/sandbox", oauth2.LoginRequired, DomainCheck, NewSandBoxController().Post()) m.Group(URLAuthBaseV1, func(r martini.Router) { r.Put(APIKey, authKey.Put()) r.Get(APIKey, authKey.Get()) r.Delete(APIKey, authKey.Delete()) }, oauth2.LoginRequired, DomainCheck) m.Group(URLOrgBaseV1, func(r martini.Router) { pcfOrg := NewOrgController(mongoConn, authClient) r.Put(OrgUser, pcfOrg.Put()) r.Get(OrgUser, pcfOrg.Get()) }, oauth2.LoginRequired, DomainCheck) }
func InitDebugMiddleware(m *martini.ClassicMartini) { m.Use(PARAMS) m.Use(DB()) m.Use(sessions.Sessions("lol_session", sessions.NewCookieStore([]byte("secret123")))) m.Use(render.Renderer(render.Options{Directory: TemplatesLocation})) m.Use(martini.Static("resources/public", martini.StaticOptions{Prefix: "/public"})) SetId("1", "10153410152015744", "Sean Myers") // Me. Set these to act like facebook, using a nice cache }
func Initialize(m *martini.ClassicMartini) { fmt.Println("Running in production environment") newRelicLicenseKey := os.Getenv("NEW_RELIC_LICENSE_KEY") if len(newRelicLicenseKey) > 0 { gorelic.InitNewrelicAgent(newRelicLicenseKey, AppName, true) m.Use(gorelic.Handler) } }
// Configure creates a default newrelic client and adds middleware and such func Configure(m *martini.ClassicMartini) error { cfg, err := config.LoadEnv() if err != nil { return err } ctl := control.NewAgentController(cfg) m.MapTo(ctl, (*control.Controller)(nil)) m.Use(NewRelicMiddleware(cfg)) return nil }
func configRender(m *martini.ClassicMartini) { m.Use(render.Renderer(render.Options{ Directory: "templates", // Specify what path to load the templates from. Layout: "layout", // Specify a layout template. Layouts can call {{ yield }} to render the current template. Extensions: []string{".tmpl.html", ".html", ".tmpl"}, // Specify extensions to load for templates. //Funcs: []template.FuncMap{AppHelpers}, // Specify helper function maps for templates to access. //Delims: render.Delims{"{[{", "}]}"}, // Sets delimiters to the specified strings. //Charset: "UTF-8", // Sets encoding for json and html content-types. Default is "UTF-8". //IndentJSON: true, // Output human readable JSON //IndentXML: true, // Output human readable XML //HTMLContentType: "application/xhtml+xml", // Output XHTML content type instead of default "text/html" })) }
func Configure(m *martini.ClassicMartini) { m.Group("/humidity", func(r martini.Router) { r.Post("", humidity.Post) r.Get("", humidity.Get) }) m.Get("/current/humidity", current_humidity.Get) m.Group("/", func(r martini.Router) { r.Get("", index.Get) }) static := martini.Static("templates", martini.StaticOptions{Fallback: "/index.tmpl", Exclude: "/api/v"}) m.NotFound(static, http.NotFound) m.Use(martini.Static("static")) }
func mid(m *martini.ClassicMartini) { //载入config文件信息 conf := goini.SetConfig("./config/conf.ini") //port := conf.GetValue("route", "port") //m.RunOnAddr(":" + port) db := helper.NewDb() m.Map(conf) m.Map(db) //过滤器handle m.Use(func(c martini.Context, log *log.Logger) { log.Println("before a request") c.Next() log.Println("after a request") }) }
func main() { var ( err error cmdConfig *config.CommandLineConfiguration cfg *config.Config m *martini.ClassicMartini log *logging.Logger ) cmdConfig, err = config.GetCommandLineConfiguration() if err != nil { panic(err) } cfg, err = config.GetConfig(cmdConfig.ConfigFilePath) if err != nil { panic(err) } defer cfg.Logger.LogFile.Close() log, err = logger.GetLogger(&cfg.Logger) if err != nil { panic(err) } session, err := db.GetSession(&cfg.DatabaseConnectOpts) if err != nil { panic(err) } m = martini.Classic() m.Map(log) m.Map(&cfg.WebSocketConfig) m.Map(&cfg.HttpServer) m.Map(&cfg) m.Map(session) m.Use(render.Renderer(render.Options{ Layout: "base", })) routing.Configure(m) log.Info("Listening") m.RunOnAddr(cfg.ListenHost + ":" + cfg.ListenPort) log.Info("Listening") }
func setMiddleware(m *martini.ClassicMartini) { setDB(m) m.Use(martini.Static("public")) m.Use(render.Renderer(render.Options{ Layout: "layout", })) store := sessions.NewCookieStore([]byte(os.Getenv("SECRET"))) m.Use(sessions.Sessions("session", store)) m.Use(csrf.Generate(&csrf.Options{ Secret: os.Getenv("CSRF"), SessionKey: "user", ErrorFunc: func(res http.ResponseWriter) { http.Error(res, "CSRF Token Failure", http.StatusUnauthorized) }, })) }
func configureAssets(m *mart.ClassicMartini, analyticsConfig AnalyticsConfig, logger boshlog.Logger) { assetsIDBytes, err := ioutil.ReadFile("./public/assets-id") ensureNoErr(logger, "Failed to find assets ID", err) assetsID := strings.TrimSpace(string(assetsIDBytes)) assetsFuncs := template.FuncMap{ "cssPath": func(fileName string) (string, error) { return "/" + assetsID + "/stylesheets/" + fileName, nil }, "jsPath": func(fileName string) (string, error) { return "/" + assetsID + "/javascript/" + fileName, nil }, "imgPath": func(fileName string) (string, error) { return "/" + assetsID + "/images/" + fileName, nil }, } analyticsConfigFuncs := template.FuncMap{ "analyticsConfig": func() AnalyticsConfig { return analyticsConfig }, } htmlFuncs := template.FuncMap{ "href": func(s string) template.HTMLAttr { return template.HTMLAttr(fmt.Sprintf(" href='%s' ", s)) }, } // Use prefix to cache bust images, stylesheets, and js m.Use(mart.Static( "./public", mart.StaticOptions{ Prefix: assetsID, }, )) // Make sure docs' images are available as `docs/images/X` m.Use(mart.Static( "./templates/docs/images", mart.StaticOptions{ Prefix: "docs/images", }, )) m.Use(martrend.Renderer( martrend.Options{ Layout: "layout", Directory: "./templates", Extensions: []string{".tmpl", ".html"}, Funcs: []template.FuncMap{assetsFuncs, analyticsConfigFuncs, htmlFuncs}, }, )) }
func Initialize(m *martini.ClassicMartini) { m.Use(render.Renderer(render.Options{ Layout: "layout", Directory: "templates", Extensions: []string{".tpl", ".html"}, Charset: "UTF-8", })) store := sessions.NewCookieStore([]byte("vim-tips-secure")) m.Use(sessions.Sessions("my_session", store)) InitConnections() m.Use(InitDB()) InitRouters(m) }
func Module(m *martini.ClassicMartini) { // Making sessions available for handles store := sessions.NewCookieStore([]byte("5bf1fd927dfb8679496a2e6cf00cbe50c1c87145")) m.Use(sessions.Sessions("blah_default", store)) m.Use(func(c martini.Context, session sessions.Session) { // Making template available for handles template := &TemplateData{} template.SessionMessage = &Messages{} template.SessionMessage.SetSession(session) c.Map(template) // Making session available for handles c.Map(template.SessionMessage) }) // Setting active request uri for template helper m.Use(SetupActivePage) }
func addPolicy(m *martini.ClassicMartini, limit uint64, within time.Duration, options ...*Options) { m.Use(Policy(&Quota{ Limit: limit, Within: within, }, options...)) }
func Initialize(m *martini.ClassicMartini) { fmt.Println("Running in debug environment") m.Use(martini.Static("private")) }