feat(scan): scaffold Scan Service - #44
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR scaffolds a new Scan Service within services/scan, providing an HTTP API backed by a SQLite persistence layer and basic unit tests, aligning with Issue #11’s scaffold + storage acceptance criteria.
Changes:
- Added a SQLite-backed store with
Scan/Findingmodels and CRUD-style operations (create, get by id, list). - Implemented HTTP handlers + routing for
/healthz,/readyz,POST /scan,GET /scan/{id}, andGET /scans, with structured JSON logging. - Added unit tests covering the store and handler endpoints, plus service startup wiring in
cmd/server.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| services/scan/internal/store/store.go | SQLite schema + store methods for creating, fetching, and listing scans |
| services/scan/internal/store/store_test.go | Unit tests for store create/get/list behaviors |
| services/scan/internal/store/model.go | Scan, Finding, and ScanStatus model definitions |
| services/scan/internal/handler/handler.go | HTTP routes, handlers, JSON helpers, and request logging middleware |
| services/scan/internal/handler/handler_test.go | Handler tests for health endpoints, scan lifecycle, and invalid request rejection |
| services/scan/go.mod | New Go module for the scan service and its direct/indirect dependencies |
| services/scan/go.sum | Dependency checksum entries for the scan service module |
| services/scan/cmd/server/main.go | Service entrypoint wiring logger, store, router, and graceful shutdown |
| services/scan/.env.example | Example environment variables for port and DB path |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+106
to
+107
| scan.CreatedAt.Format(time.RFC3339Nano), | ||
| scan.UpdatedAt.Format(time.RFC3339Nano), |
Comment on lines
+115
to
+132
| type statusRecorder struct { | ||
| http.ResponseWriter | ||
| status int | ||
| } | ||
|
|
||
| func (r *statusRecorder) WriteHeader(status int) { | ||
| r.status = status | ||
| r.ResponseWriter.WriteHeader(status) | ||
| } | ||
|
|
||
| func (h *Handler) requestLogger(next http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| start := time.Now() | ||
| recorder := &statusRecorder{ResponseWriter: w, status: http.StatusOK} | ||
| next.ServeHTTP(recorder, r) | ||
| h.logger.Info("http request", "method", r.Method, "path", r.URL.Path, "status", recorder.status, "duration_ms", time.Since(start).Milliseconds()) | ||
| }) | ||
| } |
Comment on lines
+57
to
+62
| func (h *Handler) createScan(w http.ResponseWriter, r *http.Request) { | ||
| var request createScanRequest | ||
| decoder := json.NewDecoder(r.Body) | ||
| decoder.DisallowUnknownFields() | ||
| if err := decoder.Decode(&request); err != nil { | ||
| writeError(w, http.StatusBadRequest, "invalid JSON request") |
Comment on lines
+61
to
+65
| if err := decoder.Decode(&request); err != nil { | ||
| writeError(w, http.StatusBadRequest, "invalid JSON request") | ||
| return | ||
| } | ||
| request.Target = strings.TrimSpace(request.Target) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11
What
Adds the initial Scan Service foundation.
How I verified