@@ -14,6 +14,7 @@ import (
1414 "github.com/gin-contrib/static"
1515 "github.com/gin-gonic/gin"
1616 "github.com/hhftechnology/middleware-manager/api/handlers"
17+ "github.com/hhftechnology/middleware-manager/services"
1718)
1819
1920// Server represents the API server
@@ -24,6 +25,8 @@ type Server struct {
2425 middlewareHandler * handlers.MiddlewareHandler
2526 resourceHandler * handlers.ResourceHandler
2627 configHandler * handlers.ConfigHandler
28+ dataSourceHandler * handlers.DataSourceHandler
29+ configManager * services.ConfigManager
2730}
2831
2932// ServerConfig contains configuration options for the server
@@ -36,7 +39,7 @@ type ServerConfig struct {
3639}
3740
3841// NewServer creates a new API server
39- func NewServer (db * sql.DB , config ServerConfig ) * Server {
42+ func NewServer (db * sql.DB , config ServerConfig , configManager * services. ConfigManager ) * Server {
4043 // Set gin mode based on debug flag
4144 if ! config .Debug {
4245 gin .SetMode (gin .ReleaseMode )
@@ -77,6 +80,7 @@ func NewServer(db *sql.DB, config ServerConfig) *Server {
7780 middlewareHandler := handlers .NewMiddlewareHandler (db )
7881 resourceHandler := handlers .NewResourceHandler (db )
7982 configHandler := handlers .NewConfigHandler (db )
83+ dataSourceHandler := handlers .NewDataSourceHandler (configManager )
8084
8185 // Setup server
8286 server := & Server {
@@ -85,6 +89,8 @@ func NewServer(db *sql.DB, config ServerConfig) *Server {
8589 middlewareHandler : middlewareHandler ,
8690 resourceHandler : resourceHandler ,
8791 configHandler : configHandler ,
92+ dataSourceHandler : dataSourceHandler ,
93+ configManager : configManager ,
8894 srv : & http.Server {
8995 Addr : ":" + config .Port ,
9096 Handler : router ,
@@ -132,20 +138,22 @@ func (s *Server) setupRoutes(uiPath string) {
132138 resources .DELETE ("/:id/middlewares/:middlewareId" , s .resourceHandler .RemoveMiddleware )
133139
134140 // Router configuration routes
135- resources .PUT ("/:id/config/http" , s .configHandler .UpdateHTTPConfig ) // HTTP entrypoints
136- resources .PUT ("/:id/config/tls" , s .configHandler .UpdateTLSConfig ) // TLS certificate domains
137- resources .PUT ("/:id/config/tcp" , s .configHandler .UpdateTCPConfig ) // TCP SNI routing
138- resources .PUT ("/:id/config/headers" , s .configHandler .UpdateHeadersConfig ) // Custom Host headers
139- resources .PUT ("/:id/config/priority" , s .configHandler .UpdateRouterPriority ) // Router priority
141+ resources .PUT ("/:id/config/http" , s .configHandler .UpdateHTTPConfig )
142+ resources .PUT ("/:id/config/tls" , s .configHandler .UpdateTLSConfig )
143+ resources .PUT ("/:id/config/tcp" , s .configHandler .UpdateTCPConfig )
144+ resources .PUT ("/:id/config/headers" , s .configHandler .UpdateHeadersConfig )
145+ resources .PUT ("/:id/config/priority" , s .configHandler .UpdateRouterPriority )
146+ }
147+
148+ // Data source routes
149+ datasource := api .Group ("/datasource" )
150+ {
151+ datasource .GET ("" , s .dataSourceHandler .GetDataSources )
152+ datasource .GET ("/active" , s .dataSourceHandler .GetActiveDataSource )
153+ datasource .PUT ("/active" , s .dataSourceHandler .SetActiveDataSource )
154+ datasource .PUT ("/:name" , s .dataSourceHandler .UpdateDataSource )
155+ datasource .POST ("/:name/test" , s .dataSourceHandler .TestDataSourceConnection )
140156 }
141- // Data source routes
142- datasource := api .Group ("/datasource" )
143- {
144- datasource .GET ("" , s .dataSourceHandler .GetDataSources )
145- datasource .GET ("/active" , s .dataSourceHandler .GetActiveDataSource )
146- datasource .PUT ("/active" , s .dataSourceHandler .SetActiveDataSource )
147- datasource .PUT ("/:name" , s .dataSourceHandler .UpdateDataSource )
148- }
149157 }
150158
151159 // Serve the React app
0 commit comments