示例#1
0
文件: main.go 项目: mvpmvh/interpose
func main() {
	router := mux.NewRouter()

	router.HandleFunc("/{user}", func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(w, "Welcome to the home page, %s!", mux.Vars(req)["user"])
	})

	mw := interpose.New()

	// Use logrus
	x := negroni.Handler(negronilogrus.NewMiddleware())
	mw.Use(adaptors.FromNegroni(x))

	// Apply the router. By adding it last, all of our other middleware will be
	// executed before the router, allowing us to modify headers before any
	// output has been generated.
	mw.UseHandler(router)

	// Launch and permit graceful shutdown, allowing up to 10 seconds for existing
	// connections to end
	graceful.Run(":3001", 10*time.Second, mw)
}
示例#2
0
func main() {
	// Instantiate a new router
	r := httprouter.New()
	n := negroni.Classic()

	// Get a UserController instance
	//	uc := controllers.NewUserController(getSession())
	//	cc := controllers.NewCustomerController(getSession())
	//
	//	// Get a user resource
	//	r.GET("/user/:id", uc.GetUser)
	//	r.GET("/customer/:id",cc.GetCustomer)
	//
	//	// Create a new user
	//	r.POST("/user", uc.CreateUser)
	//	r.POST("/customer",cc.CreateCustomer)
	//
	//	r.PUT("/customer/:id",cc.UpdateCustomer)
	//
	//	// Remove an existing user
	//	r.DELETE("/user/:id", uc.RemoveUser)
	//	r.DELETE("/customer/:id",cc.RemoveCustomer)

	// Fire up the server
	r.HandlerFunc("GET", "/login", getToken)
	r.Handler("GET", "/api",
		negroni.New(negroni.HandlerFunc(AuthMiddleware1), negroni.HandlerFunc(APIHandler1), negroni.Handler(CreateCustomer1)))
	//	r.Handler("POST","/customer",
	//		negroni.New(negroni.HandlerFunc(AuthMiddleware1),negroni.HandlerFunc(APIHandler1),cc.CreateCustomer))
	n.UseHandler(r)
	http.ListenAndServe("localhost:8080", n)
}