@@ -30,6 +30,14 @@ type httpServer struct {
3030 server * http.Server
3131}
3232
33+ // This represents mapping between a path and an http Handler.
34+ // Note a handler can be created out of any func with type signature
35+ // func(w http.ResponseWriter, r *http.Request) via HandleFunc()
36+ type Handler struct {
37+ path string
38+ handlerFunc http.Handler
39+ }
40+
3341// Some Feast types aren't supported during JSON conversion
3442type repeatedValue struct {
3543 stringVal []string
@@ -339,15 +347,17 @@ func recoverMiddleware(next http.Handler) http.Handler {
339347 })
340348}
341349
342- func (s * httpServer ) Serve (host string , port int ) error {
350+ func (s * httpServer ) Serve (host string , port int , handlers [] Handler ) error {
343351 if strings .ToLower (os .Getenv ("ENABLE_DATADOG_TRACING" )) == "true" {
344352 tracer .Start (tracer .WithRuntimeMetrics ())
345353 defer tracer .Stop ()
346354 }
347355 mux := httptrace .NewServeMux ()
348- mux .Handle ("/get-online-features" , recoverMiddleware (http .HandlerFunc (s .getOnlineFeatures )))
349- mux .Handle ("/metrics" , promhttp .Handler ())
350- mux .HandleFunc ("/health" , healthCheckHandler )
356+
357+ for _ , handler := range handlers {
358+ mux .Handle (handler .path , handler .handlerFunc )
359+ }
360+
351361 s .server = & http.Server {Addr : fmt .Sprintf ("%s:%d" , host , port ), Handler : mux , ReadTimeout : 5 * time .Second , WriteTimeout : 10 * time .Second , IdleTimeout : 15 * time .Second }
352362 err := s .server .ListenAndServe ()
353363 // Don't return the error if it's caused by graceful shutdown using Stop()
@@ -358,6 +368,23 @@ func (s *httpServer) Serve(host string, port int) error {
358368 return err
359369}
360370
371+ func DefaultHttpHandlers (s * httpServer ) []Handler {
372+ return []Handler {
373+ {
374+ path : "/get-online-features" ,
375+ handlerFunc : recoverMiddleware (http .HandlerFunc (s .getOnlineFeatures )),
376+ },
377+ {
378+ path : "/metrics" ,
379+ handlerFunc : promhttp .Handler (),
380+ },
381+ {
382+ path : "/health" ,
383+ handlerFunc : http .HandlerFunc (healthCheckHandler ),
384+ },
385+ }
386+ }
387+
361388func healthCheckHandler (w http.ResponseWriter , r * http.Request ) {
362389 w .WriteHeader (http .StatusOK )
363390 fmt .Fprintf (w , "Healthy" )
0 commit comments