// NewServer initializes a Server with a DB and sets up its routes. func NewServer(conf *config.Config, schema *gumshoe.Schema) *Server { s := &Server{Config: conf} s.loadDB(schema) mux := pat.New() mux.Put("/insert", s.HandleInsert) mux.Get("/dimension_tables/{name}", s.HandleSingleDimension) mux.Get("/dimension_tables", s.HandleDimensionTables) mux.Post("/query", s.HandleQuery) mux.Get("/metricz", s.HandleMetricz) mux.Get("/debug/rows", s.HandleDebugRows) mux.Get("/statusz", s.HandleStatusz) mux.Get("/", s.HandleRoot) s.Handler = mux go s.RunPeriodicFlushes() go s.RunPeriodicStatsChecks() return s }
func NewRouter(shards []string, schema *gumshoe.Schema) *Router { transport := &http.Transport{MaxIdleConnsPerHost: 8} r := &Router{ Schema: schema, Shards: shards, Client: &http.Client{Transport: transport}, } mux := pat.New() mux.Put("/insert", r.HandleInsert) mux.Get("/dimension_tables/{name}", r.HandleSingleDimension) mux.Get("/dimension_tables", r.HandleUnimplemented) mux.Post("/query", r.HandleQuery) mux.Get("/metricz", r.HandleUnimplemented) mux.Get("/debug/rows", r.HandleUnimplemented) mux.Get("/statusz", r.HandleStatusz) mux.Get("/", r.HandleRoot) r.Handler = apachelog.NewDefaultHandler(mux) return r }