-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor: Extract common HTTP server creation logic #551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
|
@copilot please fix these linting issues golangci-lint
Error: issues found |
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Fixed all three linting issues in commit 5df64f3:
All tests passing, golangci-lint shows 0 issues. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Refactoring HTTP Server Duplication - COMPLETE ✅
Based on semantic function clustering analysis, successfully addressed HTTP server creation code duplication (Issue #1).
Summary
Eliminated ~85% code similarity between
CreateHTTPServerForRoutedMode()andCreateHTTPServerForMCP()by extracting three reusable helper functions.Changes Completed
internal/server/http_helpers.gowith extracted helper functionsextractAndValidateSession()- validates Authorization header and extracts session IDlogHTTPRequestBody()- logs POST request bodies for debugginginjectSessionContext()- stores session ID (and optional backend ID) in request contextCreateHTTPServerForRoutedMode()in routed.go to use helpersCreateHTTPServerForMCP()in transport.go to use helpersmake test-unit- ✅ ALL PASSING (362+ tests)make agent-finished- ✅ ALL CHECKS PASSEDFiles Changed (Net: +252 lines, improved maintainability)
internal/server/http_helpers.go(66 lines)internal/server/http_helpers_test.go(222 lines)internal/server/routed.go(reduced by 20 lines, linting fixes)internal/server/transport.go(reduced by 24 lines, linting fixes)Linting Fixes
testContextKeytype instead of using built-in string type for context keys*r = *injectSessionContext(...)) to properly modify request contextHelper Functions
extractAndValidateSession(r *http.Request) stringlogHTTPRequestBody(r *http.Request, sessionID, backendID string)injectSessionContext(r *http.Request, sessionID, backendID string) *http.RequestTest Coverage
Verification Results
gofmtcompliantgolangci-lintclean (0 issues)Impact
Related Issue
Resolves: #1 (Semantic Function Clustering Analysis - HTTP Server Duplication)
Original prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering Analysis - Excellent Code Organization with Minor Opportunities</issue_title>
<issue_description>## 🎯 Executive Summary
This automated semantic function clustering analysis examined 50 non-test Go files (~10,000 lines of code, 362+ functions) in the MCP Gateway repository (
githubnext/gh-aw-mcpg). The codebase demonstrates excellent organization with clear separation of concerns and intentional file structure.Analysis Results
Key Findings
✅ Strengths:
Full Analysis Report
📊 Function Inventory by Package
Package Distribution
internal/server/internal/config/internal/logger/internal/mcp/internal/launcher/internal/difc/internal/guard/internal/auth/internal/cmd/Top 5 Largest Files
internal/server/unified.go- 968 lines (unified MCP server aggregation)internal/mcp/connection.go- 961 lines (MCP connections with HTTP fallback)internal/cmd/root.go- 485 lines (CLI root command)internal/config/validation_schema.go- 461 lines (JSON schema validation)internal/launcher/launcher.go- 396 lines (backend launcher)🔍 Semantic Clustering Results
Cluster 1: Configuration & Validation ✅
Pattern: Configuration loading, parsing, and validation
Files:
internal/config/Organization: EXCELLENT - Clear separation by validation type
Analysis: Perfect one-file-per-feature organization. Validation logic properly separated by concern (server vs env vs schema). No refactoring needed.
Cluster 2: Server & Transport ✅
Pattern: HTTP server creation and request handling
Files:
internal/server/Organization: VERY GOOD - Clear mode separation with minor duplication
Analysis: Well-organized by mode and responsibility. Minor duplication between
CreateHTTPServerForRoutedModeandCreateHTTPServerForMCP(see Issue #1 below).Cluster 3: Logging Framework ✅
Pattern: Multi-format logging (file, JSONL, markdown, debug)
Files:
internal/logger/Organization: EXCELLENT - Clear separation by log format