Video summary
Golang Microservices Full Course #09 - Code Review & Bug Fixing
Main summary
Key takeaways
Main ideas & lessons conveyed
- The episode focuses on code review and bug fixing for a Go (Golang) microservices / microservices-like wallet/transaction system, continuing from a previous episode about optimistic locking.
- Multiple issues are identified and corrected across:
- JSON struct tags / struct definitions (using the correct
json:"..."format and separators). - Repository/query handling (avoiding dead code and ensuring correct behavior when values are null/empty).
- Timestamp handling after optimistic lock updates (ensuring
created_at/updated_atbehavior aligns with DB defaults). - HTTP handler/controller implementation for transaction endpoints, including middleware-based authorization and request validation.
- API routing wiring (ensuring the correct handler is attached to the correct route).
- JSON struct tags / struct definitions (using the correct
Methodology / step-by-step actions shown
A) Bug fix: incorrect JSON/tag syntax in Go models
- Review transaction-related model files in the
transactionfolder (e.g.,tx.goand related domain files). - Identify struct tag syntax that uses an incorrect separator/pattern.
- Replace it with the correct Go JSON tag syntax:
- Use
json:"fieldName"instead of the wrong form.
- Use
- Apply the fix consistently across all affected occurrences (the speaker checks multiple lines/files).
B) Bug fix: repository/query null handling (sender wallet ID)
- Locate the repository file responsible for “get by id…” / scanning logic.
- Observe that the
senderis “not filled” by the scan function. - Identify a conditional guard that becomes dead code because the sender validity condition can’t be met.
- Update logic so that if the sender wallet ID is null:
- The code should not silently continue.
- The function should panic or return an error, since a null sender wallet ID is invalid for the intended flow.
C) Bug fix: optimistic lock / timestamp mismatch
- After optimistic lock updates in the transfer service, notice the sender wallet timestamp (or last-updated field) still shows the prior value.
- Check whether the database schema already defines default/current timestamp behavior.
- If the DB uses
default current_timestamp(or equivalent), then manual timestamp overrides may be unnecessary.
- If the DB uses
- Remove redundant manual timestamp update code or change it to rely on DB defaults / consistent
nowhandling.- The speaker suggests deleting redundant timestamp overrides or adjusting based on the DB migration.
D) Implement missing transaction handler / controller
- Create or locate the handler package and implement a
TransactionHandlerthat depends on transaction-related services. - Ensure handler wiring references the correct service type (not accidentally mixing ledger service vs transaction service).
- Implement the endpoint handler function (the “transaction transfer handler” flow), including:
- Extract
user_idfrom middleware claims (JWT claims are referenced). - If
user_idis missing:- Return a custom error with:
- HTTP status: 401 Unauthorized
- Message: “user context not found”
- Return a custom error with:
- Bind request body into a request struct (including validation and binding).
- Call the service method (e.g.,
svc.Transfer(...)) with:- request context
- sender user id (string)
- transaction transfer request model
- If service returns an error:
- Return an error JSON response with the appropriate HTTP status and message.
- If successful:
- Return a success response message such as “transaction successful”.
- Extract
E) Route registration / main wiring
- Edit
main.go(or routing setup). - Wire the transaction transfer route to the correct handler function.
- Ensure the route method is correct.
- The speaker mentions fixing a routing/handler mismatch (e.g., issues related to reflection/signature compatibility).
- Confirm request validation rules are correctly formatted:
- Remove spaces after commas in validation rules (
a,binstead ofa, b).
- Remove spaces after commas in validation rules (
- Ensure JSON/field tags and validation expectations match what the request body actually provides.
F) Verify with local testing (Docker + Postman)
- Start the app using:
go run cmd/main.go
- Use Postman to test:
- Register/login to obtain an access token for the sender user.
- Send a POST request to the transaction transfer endpoint.
- Include fields such as:
- receiver email
- amount (e.g., 50,000, later increased to 100 for balance testing)
- description
- item potency key / potency key (example key mentioned:
test transfer 001)
- Test failure cases:
- “transfer missing token” → confirms auth token requirement.
- “receiver email … filter doesn’t … receiver email” (likely validation/search mismatch).
- “insufficient balance” for the sender wallet.
- Fix and retest:
- Temporarily adjust sender balance (the speaker increases/update it so the transfer can succeed).
- Confirm:
- response includes updated balances
- transaction success message is returned
- DB/ledger entries reflect correct debit/credit and transaction ID
- ledger rows should reference sender/receiver wallet IDs and associate them with the transaction.
G) Top-up handling plan (not fully implemented yet)
- The episode discusses adding top up capability but notes it’s not fully implemented in the API/service yet.
- Current approach:
- Create/branch work for bug fixing and review (e.g.,
feature/009-bugfixing). - For testing, directly inject/update balances in the database (manual updates).
- Create/branch work for bug fixing and review (e.g.,
- Future plan:
- Real top up requires payment integration and virtual bank/account logic.
- Add provider validation first, then credit the e-wallet.
H) Git workflow reminder (course practice)
- Normally:
- Push to a feature branch
- Open/merge via pull request to
master - Pull updates before continuing development
- For tutorial purposes, the speaker may simplify by pushing directly to
master.
Speakers / sources featured
- Primary speaker: Unnamed course instructor (guides coding/testing workflow throughout).
- Other sources/guests: None explicitly named.
Rate this summary
Your feedback will help improve summaries.
Improve this summary
Reprocess with a stronger model when the summary feels incomplete or inaccurate.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.