当前位置: 首页>>代码示例>>Golang>>正文


Golang negroni.New函数代码示例

本文整理汇总了Golang中github.com/codegangsta/negroni.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: BuildRoutes

// BuildRoutes returns the routes for the application.
func BuildRoutes() http.Handler {
	router := mux.NewRouter()

	router.HandleFunc("/", HomeHandler)
	router.HandleFunc("/login-success", LoginSuccessHandler)
	router.HandleFunc("/verify", VerifyHandler)
	router.HandleFunc("/logout", LogoutHandler)
	router.HandleFunc("/game", GameHandler)

	// profile routes with LoginRequiredMiddleware
	profileRouter := mux.NewRouter()
	profileRouter.HandleFunc("/profile", ProfileHandler)

	router.PathPrefix("/profile").Handler(negroni.New(
		negroni.HandlerFunc(LoginRequiredMiddleware),
		negroni.Wrap(profileRouter),
	))

	// apply the base middleware to the main router
	n := negroni.New(
		negroni.HandlerFunc(CsrfMiddleware),
		negroni.HandlerFunc(UserMiddleware),
	)
	n.UseHandler(router)

	return n
}
开发者ID:gotstago,项目名称:go-tarabish,代码行数:28,代码来源:routes.go

示例2: InitRoutes

//InitRoutes sets up our routes, whether anonymous or authenticated.
//Utilizing Negroni so we can have multiple handlers, each one with the ability to call the next.
func InitRoutes() *mux.Router {
	router := mux.NewRouter().StrictSlash(true)

	//anonymous routes
	//Get Environment
	router.Handle("/",
		negroni.New(
			negroni.HandlerFunc(controllers.GetRoute),
		)).Methods("GET")
	//Get Milestones By DealID
	router.Handle("/milestones/complete/{dealGUID}",
		negroni.New(
			negroni.HandlerFunc(controllers.GetDealCompletedMilestonesByDealGUID),
		)).Methods("GET")
	//Get Milestones with complete status By DealID
	router.Handle("/milestones/{dealGUID}",
		negroni.New(
			negroni.HandlerFunc(controllers.GetMilestonesByDealGUID),
		)).Methods("GET")
	//Post events for a deal
	router.Handle("/event/{dealGUID}/{eventName}",
		negroni.New(
			negroni.HandlerFunc(controllers.DealEventHandler),
		)).Methods("GET")
	//authenticated routes
	//...

	return router
}
开发者ID:SolarCity,项目名称:ftb_milestoneapi,代码行数:31,代码来源:router.go

示例3: InitPost

func InitPost(r *mux.Router) {
	l4g.Debug("Initializing post api routes")

	r.Handle("/posts/{post_id}", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(getPost),
	)).Methods("GET")

	sr := r.PathPrefix("/channels/{id}").Subrouter()

	sr.Handle("/create", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(createPost),
	)).Methods("POST")

	sr.Handle("/update", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(updatePost),
	)).Methods("POST")

	// {offset:[0-9]+}/{limit:[0-9]+}
	sr.Handle("/posts/", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(getPosts),
	)).Methods("GET")
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:26,代码来源:post.go

示例4: Run

func (a *Api) Run() error {
	globalMux := http.NewServeMux()

	router := mux.NewRouter()
	router.HandleFunc("/", a.index).Methods("GET")
	router.HandleFunc("/create", a.create).Methods("POST")
	router.HandleFunc("/ip", a.getIP).Methods("GET")
	router.HandleFunc("/state", a.getState).Methods("GET")
	router.HandleFunc("/start", a.start).Methods("GET")
	router.HandleFunc("/kill", a.kill).Methods("GET")
	router.HandleFunc("/remove", a.remove).Methods("GET")
	router.HandleFunc("/restart", a.restart).Methods("GET")
	router.HandleFunc("/stop", a.stop).Methods("GET")
	// enable auth if token is present
	if a.config.AuthToken != "" {
		am := auth.NewAuthMiddleware(a.config.AuthToken)
		globalMux.Handle("/", negroni.New(
			negroni.HandlerFunc(am.Handler),
			negroni.Wrap(http.Handler(router)),
		))
	} else {

		globalMux.Handle("/", router)
	}

	log.Infof("rivet version %s", version.FULL_VERSION)
	log.Infof("listening: addr=%s", a.config.ListenAddr)
	n := negroni.New()
	n.UseHandler(globalMux)
	return http.ListenAndServe(a.config.ListenAddr, n)
}
开发者ID:carriercomm,项目名称:rivet,代码行数:31,代码来源:api.go

示例5: serverRun

func serverRun(cmd *cobra.Command, args []string) {
	// MongoDB setup
	CreateUniqueIndexes()
	// Web Server Setup
	CreateStore()
	webRouter := CreateWebRouter()
	teamRouter := CreateTeamRouter()

	app := negroni.New()
	webRouter.PathPrefix("/").Handler(negroni.New(
		negroni.HandlerFunc(RequireLogin),
		negroni.Wrap(teamRouter),
	))
	app.Use(negroni.NewLogger())
	app.Use(negroni.NewStatic(http.Dir("static")))
	app.Use(negroni.HandlerFunc(CheckSessionID))

	app.UseHandler(webRouter)

	l := log.New(os.Stdout, "[negroni] ", 0)
	http_port := viper.GetString("server.http_port")
	https_port := viper.GetString("server.https_port")
	cert := viper.GetString("server.cert")
	key := viper.GetString("server.key")

	l.Printf("Server running at: https://%s:%s", viper.GetString("server.ip"), https_port)

	go http.ListenAndServe(":"+http_port, http.HandlerFunc(redir))

	l.Fatal(http.ListenAndServeTLS(":"+https_port, cert, key, app))
}
开发者ID:pereztr5,项目名称:cyboard,代码行数:31,代码来源:server.go

示例6: SetAuthenticationRoutes

func SetAuthenticationRoutes(router *mux.Router) *mux.Router {

	tokenRouter := mux.NewRouter()

	tokenRouter.Handle("/api/auth/token/new", negroni.New(
		negroni.HandlerFunc(controllers.Login),
	)).Methods("POST")

	tokenRouter.Handle("/api/auth/logout", negroni.New(
		negroni.HandlerFunc(auth.RequireTokenAuthentication),
		negroni.HandlerFunc(controllers.Logout),
	))

	tokenRouter.Handle("/api/auth/token/refresh", negroni.New(
		negroni.HandlerFunc(auth.RequireTokenAuthentication),
		negroni.HandlerFunc(controllers.RefreshToken),
	)).Methods("GET")

	tokenRouter.Handle("/api/auth/token/validate", negroni.New(
		negroni.HandlerFunc(auth.RequireTokenAuthentication),
		negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
			w.WriteHeader(http.StatusOK)
		}),
	))

	router.PathPrefix("/api/auth").Handler(negroni.New(
		negroni.Wrap(tokenRouter),
	))

	return router
}
开发者ID:malloc-fi,项目名称:vantaa,代码行数:31,代码来源:authentication.go

示例7: Routing

// Routing ... list of routing services
func (c AccountRouter) Routing(router *mux.Router, apiprefix string) {
	baseModel := base.BaseModel{Status: "ACTIVE", CreatedAt: time.Now()}
	httpUtilFunc := utilFunc.HTTPUtilityFunctions{}
	account := controllers.AccountController{c.DataStore, baseModel, httpUtilFunc}

	router.Handle(apiprefix+"/accounts",
		negroni.New(
			negroni.HandlerFunc(authentication.RequireTokenAuthentication),
			negroni.HandlerFunc(account.CreateAccount),
		)).Methods("POST")

	router.Handle(apiprefix+"/account/categories",
		negroni.New(
			negroni.HandlerFunc(authentication.RequireTokenAuthentication),
			negroni.HandlerFunc(account.CreateAccount),
		)).Methods("POST")

	router.Handle(apiprefix+"/account/fundsource",
		negroni.New(
			negroni.HandlerFunc(authentication.RequireTokenAuthentication),
			negroni.HandlerFunc(account.CreateAccountCategory),
		)).Methods("POST")

	router.Handle(apiprefix+"/account/limit",
		negroni.New(
			negroni.HandlerFunc(authentication.RequireTokenAuthentication),
			negroni.HandlerFunc(account.CreateAccountLimit),
		)).Methods("POST")
	router.Handle(apiprefix+"/account/funding",
		negroni.New(
			negroni.HandlerFunc(authentication.RequireTokenAuthentication),
			negroni.HandlerFunc(account.CreateAccountFundMapping),
		)).Methods("POST")

}
开发者ID:amosunfemi,项目名称:xtremepay,代码行数:36,代码来源:accounting.go

示例8: main

func main() {

	var wg sync.WaitGroup

	wg.Add(3)
	go func() {
		n := negroni.New()
		fmt.Println("Launching server on :3000")
		graceful.Run(":3000", 0, n)
		fmt.Println("Terminated server on :3000")
		wg.Done()
	}()
	go func() {
		n := negroni.New()
		fmt.Println("Launching server on :3001")
		graceful.Run(":3001", 0, n)
		fmt.Println("Terminated server on :3001")
		wg.Done()
	}()
	go func() {
		n := negroni.New()
		fmt.Println("Launching server on :3002")
		graceful.Run(":3002", 0, n)
		fmt.Println("Terminated server on :3002")
		wg.Done()
	}()
	fmt.Println("Press ctrl+c. All servers should terminate.")
	wg.Wait()

}
开发者ID:ZhuZhengyi,项目名称:eris-db,代码行数:30,代码来源:main.go

示例9: main

func main() {
	configuration := readConfiguration()
	dbSession := DBConnect(configuration.MongodbUrl)
	DBEnsureIndicesAndDefaults(dbSession, configuration.MongodbDatabaseName)

	// handle all requests by serving a file of the same name
	fs := http.Dir(configuration.Webapp)
	fileHandler := http.FileServer(fs)

	// setup routes
	router := mux.NewRouter()

	router.Handle("/", http.RedirectHandler("/webapp/index.html", 302))
	router.PathPrefix("/webapp").Handler(http.StripPrefix("/webapp", fileHandler))

	authRouterBase := mux.NewRouter()
	router.PathPrefix("/auth").Handler(negroni.New(DBMiddleware(dbSession, configuration.MongodbDatabaseName), negroni.Wrap(authRouterBase)))
	authRouter := authRouterBase.PathPrefix("/auth").Subrouter()
	authRouter.HandleFunc("/login", Login).Methods("POST")

	apiRouterBase := mux.NewRouter()
	router.PathPrefix("/api").Handler(negroni.New(DBMiddleware(dbSession, configuration.MongodbDatabaseName), JWTMiddleware(), negroni.Wrap(apiRouterBase)))
	apiRouter := apiRouterBase.PathPrefix("/api").Subrouter()
	apiRouter.HandleFunc("/me", Me).Methods("GET")

	http.ListenAndServe(fmt.Sprintf(":%v", configuration.Port), router)
}
开发者ID:martianov,项目名称:go-imb,代码行数:27,代码来源:go_imb.go

示例10: Routing

// Routing ... list of routing services
func (c UserRouter) Routing(router *mux.Router, apiprefix string) {
	baseModel := base.BaseModel{Status: "ACTIVE", CreatedAt: time.Now()}
	httpUtilFunc := utilFunc.HTTPUtilityFunctions{}
	userController := controllers.UserController{baseModel, httpUtilFunc, c.DataStore, c.Logger.Logger}
	securityController := controllers.SecurityController{baseModel, c.DataStore, httpUtilFunc}
	// User url mappings
	router.HandleFunc(apiprefix+"/user", userController.CreateUser).Methods("POST")

	router.HandleFunc(apiprefix+"/user/activate", userController.ActivateUser).Methods("PATCH")

	router.Handle(apiprefix+"/user/changepassword",
		negroni.New(
			negroni.HandlerFunc(authentication.RequireTokenAuthentication),
			negroni.HandlerFunc(userController.ChangePassword),
		)).Methods("PATCH")

	router.HandleFunc(apiprefix+"/token-auth", securityController.Login).Methods("POST")

	router.Handle(apiprefix+"/refresh-token-auth",
		negroni.New(
			negroni.HandlerFunc(authentication.RequireTokenAuthentication),
			negroni.HandlerFunc(controllers.RefreshToken),
		)).Methods("GET")

	router.Handle(apiprefix+"/logout",
		negroni.New(
			negroni.HandlerFunc(authentication.RequireTokenAuthentication),
			negroni.HandlerFunc(controllers.Logout),
		)).Methods("GET")

}
开发者ID:amosunfemi,项目名称:xtremepay,代码行数:32,代码来源:user.go

示例11: Init

func Init(apps map[string]interface{}, router *mux.Router) {
	Applications = apps

	// /echo/* Endpoints
	echoRouter := mux.NewRouter()
	// /* Endpoints
	pageRouter := mux.NewRouter()

	for uri, meta := range Applications {
		switch app := meta.(type) {
		case EchoApplication:
			handlerFunc := func(w http.ResponseWriter, r *http.Request) {
				echoReq := r.Context().Value("echoRequest").(*EchoRequest)
				echoResp := NewEchoResponse()

				if echoReq.GetRequestType() == "LaunchRequest" {
					if app.OnLaunch != nil {
						app.OnLaunch(echoReq, echoResp)
					}
				} else if echoReq.GetRequestType() == "IntentRequest" {
					if app.OnIntent != nil {
						app.OnIntent(echoReq, echoResp)
					}
				} else if echoReq.GetRequestType() == "SessionEndedRequest" {
					if app.OnSessionEnded != nil {
						app.OnSessionEnded(echoReq, echoResp)
					}
				} else {
					http.Error(w, "Invalid request.", http.StatusBadRequest)
				}

				json, _ := echoResp.String()
				w.Header().Set("Content-Type", "application/json;charset=UTF-8")
				w.Write(json)
			}

			if app.Handler != nil {
				handlerFunc = app.Handler
			}

			echoRouter.HandleFunc(uri, handlerFunc).Methods("POST")
		case StdApplication:
			pageRouter.HandleFunc(uri, app.Handler).Methods(app.Methods)
		}
	}

	router.PathPrefix("/echo/").Handler(negroni.New(
		negroni.HandlerFunc(validateRequest),
		negroni.HandlerFunc(verifyJSON),
		negroni.Wrap(echoRouter),
	))

	router.PathPrefix("/").Handler(negroni.New(
		negroni.Wrap(pageRouter),
	))
}
开发者ID:mikeflynn,项目名称:go-alexa,代码行数:56,代码来源:skillserver.go

示例12: RegisterRoutes

func (this *StateHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
	mux.Get("/api/state", negroni.New(
		negroni.HandlerFunc(am.RequireTokenAuthentication),
		negroni.HandlerFunc(this.Get),
	))
	mux.Post("/api/state", negroni.New(
		negroni.HandlerFunc(am.RequireTokenAuthentication),
		negroni.HandlerFunc(this.Post),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:10,代码来源:state_handler.go

示例13: RegisterRoutes

func (this *HoverflyModeHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
	mux.Get("/api/v2/hoverfly/mode", negroni.New(
		negroni.HandlerFunc(am.RequireTokenAuthentication),
		negroni.HandlerFunc(this.Get),
	))
	mux.Put("/api/v2/hoverfly/mode", negroni.New(
		negroni.HandlerFunc(am.RequireTokenAuthentication),
		negroni.HandlerFunc(this.Put),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:10,代码来源:hoverfly_mode_handler.go

示例14: main

func main() {
	//Loads environment variables from a .env file
	godotenv.Load("environment")

	var (
		clientID     = getEnv("OAUTH2_CLIENT_ID", "client_id")
		clientSecret = getEnv("OAUTH2_CLIENT_SECRET", "client_secret")
		redirectURL  = getEnv("OAUTH2_REDIRECT_URL", "redirect_url")
	)

	secureMux := http.NewServeMux()

	// Routes that require a logged in user
	// can be protected by using a separate route handler
	// If the user is not authenticated, they will be
	// redirected to the login path.
	secureMux.HandleFunc("/restrict", func(w http.ResponseWriter, req *http.Request) {
		token := oauth2.GetToken(req)
		fmt.Fprintf(w, "OK: %s", token.Access())
	})

	secure := negroni.New()
	secure.Use(oauth2.LoginRequired())
	secure.UseHandler(secureMux)

	n := negroni.New()
	n.Use(sessions.Sessions("my_session", cookiestore.New([]byte("secret123"))))
	n.Use(oauth2.Google(&oauth2.Config{
		ClientID:     clientID,
		ClientSecret: clientSecret,
		RedirectURL:  redirectURL,
		Scopes:       []string{"https://www.googleapis.com/auth/drive"},
	}))

	router := http.NewServeMux()

	//routes added to mux do not require authentication
	router.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		token := oauth2.GetToken(req)
		if token == nil || !token.Valid() {
			fmt.Fprintf(w, "not logged in, or the access token is expired")
			return
		}
		fmt.Fprintf(w, "logged in")
		return
	})

	//There is probably a nicer way to handle this than repeat the restricted routes again
	//of course, you could use something like gorilla/mux and define prefix / regex etc.
	router.Handle("/restrict", secure)

	n.UseHandler(router)

	n.Run(":3000")
}
开发者ID:anyweez,项目名称:check,代码行数:55,代码来源:main.go

示例15: RegisterRoutes

func (this *MiddlewareHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
	mux.Get("/api/middleware", negroni.New(
		negroni.HandlerFunc(am.RequireTokenAuthentication),
		negroni.HandlerFunc(this.Redirect),
	))

	mux.Post("/api/middleware", negroni.New(
		negroni.HandlerFunc(am.RequireTokenAuthentication),
		negroni.HandlerFunc(this.Redirect),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:11,代码来源:middleware_handler.go


注:本文中的github.com/codegangsta/negroni.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。