Example #1
0
func accountsRouter() cji.Router {
	r := cji.NewRouter()
	r.Use(sup1)
	r.Get("/", listAccounts)
	r.Get("/hi", hiAccounts)

	// r.Post("/", createAccount)

	r.Group(func(r cji.Router) {
		r.Use(sup2)

		r.Get("/hi2", func(c web.C, w http.ResponseWriter, r *http.Request) {
			log.Println("hi2..", c)
			w.Write([]byte("woot"))
		})
	})

	// 2nd param is optional..
	r.Route("/:accountID", func(r cji.Router) {
		r.Use(accountCtx)
		r.Get("/", getAccount)
	})

	return r
}
Example #2
0
func main() {
	r := cji.NewRouter()

	r.Use(middleware.RequestID)
	r.Use(middleware.RealIP)

	r.Get("/", apiIndex)

	r.Mount("/accounts", sup, accountsRouter())

	http.ListenAndServe(":3333", r)
}
Example #3
0
func Profiler() http.Handler {
	r := cji.NewRouter()
	r.Handle("/vars", expVars)
	r.Handle("/pprof/", pprof.Index)
	r.Handle("/pprof/cmdline", pprof.Cmdline)
	r.Handle("/pprof/profile", pprof.Profile)
	r.Handle("/pprof/symbol", pprof.Symbol)
	r.Handle("/pprof/block", pprof.Handler("block").ServeHTTP)
	r.Handle("/pprof/heap", pprof.Handler("heap").ServeHTTP)
	r.Handle("/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
	r.Handle("/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
	return r
}
Example #4
0
func main() {
	r := cji.NewRouter()

	r.Use(middleware.Logger)
	r.Use(httpcoala.Route("GET"))

	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		time.Sleep(100 * time.Millisecond) // expensive op
		w.WriteHeader(200)
		w.Write([]byte("hi"))
	})

	http.ListenAndServe(":1111", r)
}
Example #5
0
func NewRouter() http.Handler {
	conrd, err := consistentrd.New(app.Config.Cluster.LocalNode, app.Config.Cluster.Nodes)
	if err != nil {
		panic(err)
	}

	r := cji.NewRouter()

	r.Use(middleware.EnvInit)
	r.Use(middleware.RequestID)
	r.Use(middleware.RealIP)
	r.Use(RequestLogger)
	r.Use(heartbeat.Route("/ping"))

	r.Mount("/debug", middleware.NoCache, Profiler())

	r.Get("/", trackRoute("root"), func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(200)
		w.Write([]byte("."))
	})

	r.Get("/fetch", trackRoute("bucketV0GetItem"), BucketV0FetchItem) // Deprecated: for Pressilla v2 apps

	r.Get("/info", trackRoute("imageInfo"), GetImageInfo)

	r.Get("/:bucket", conrd.RouteWithParams("url"), trackRoute("bucketV1GetItem"), BucketGetIndex)
	r.Post("/:bucket", BucketImageUpload)

	r.Get("/:bucket/fetch", conrd.RouteWithParams("url"), trackRoute("bucketV1GetItem"), BucketFetchItem)

	// DEPRECATED
	r.Get("/:bucket//fetch", conrd.RouteWithParams("url"), trackRoute("bucketV1GetItem"), BucketFetchItem)

	r.Get("/:bucket/add", trackRoute("bucketAddItems"), BucketAddItems)
	r.Get("/:bucket/:key", conrd.Route(), BucketGetItem)
	r.Delete("/:bucket/:key", conrd.Route(), BucketDeleteItem)

	return r
}