✨ feat: implement API v2 with feature flag control
- Added /api/v2/greet POST endpoint with JSON request/response - Implemented ServiceV2 with Hello my friend <name>! greeting format - Added api.v2_enabled feature flag (default: false) - Extended BDD tests to cover v2 scenarios - Maintained full backward compatibility with v1 API - Added DLC_API_V2_ENABLED environment variable support - Created ADR 0010-api-v2-feature-flag.md - Updated configuration system to support API versioning
This commit is contained in:
@@ -56,6 +56,14 @@ func (s *Server) setupRoutes() {
|
||||
r.Use(s.getAllMiddlewares()...)
|
||||
s.registerApiV1Routes(r)
|
||||
})
|
||||
|
||||
// Register v2 routes if enabled
|
||||
if s.config.GetV2Enabled() {
|
||||
s.router.Route("/api/v2", func(r chi.Router) {
|
||||
r.Use(s.getAllMiddlewares()...)
|
||||
s.registerApiV2Routes(r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) registerApiV1Routes(r chi.Router) {
|
||||
@@ -66,6 +74,14 @@ func (s *Server) registerApiV1Routes(r chi.Router) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) registerApiV2Routes(r chi.Router) {
|
||||
greetServiceV2 := greet.NewServiceV2()
|
||||
greetHandlerV2 := greet.NewApiV2GreetHandler(greetServiceV2)
|
||||
r.Route("/greet", func(r chi.Router) {
|
||||
greetHandlerV2.RegisterRoutes(r)
|
||||
})
|
||||
}
|
||||
|
||||
// getAllMiddlewares returns all middleware including OpenTelemetry if enabled
|
||||
func (s *Server) getAllMiddlewares() []func(http.Handler) http.Handler {
|
||||
middlewares := []func(http.Handler) http.Handler{
|
||||
|
||||
Reference in New Issue
Block a user