Comments (2)
Re [1], [2] it's not the lack of a database.
mysql> select * from user;
+-------+-------------------+-----------+
| id | email | password |
+-------+-------------------+-----------+
| auser | [email protected] | apassword |
+-------+-------------------+-----------+
$ curl -u auser:apassword -iX "POST" "http://localhost:8080/v1/user" -H 'Content-Type: application/json' -H 'Accept: application/json' -d $'{ "email": "[email protected]", "first_name": "Ozzy", "last_name": "Osbourne", "password": "bateater666"}'
HTTP/1.1 500 Internal Server Error
Access-Control-Allow-Headers: Accept, Authorization, Content-Type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Fri, 11 Feb 2022 03:47:41 GMT
Content-Length: 17
Error adding user%
--- and ---
2022/02/11 11:47:41 Error 1045: Access denied for user 'clean_architecture_go_v2'@'localhost' (using password: YES)
[negroni] 2022-02-11T11:47:41+08:00 | 500 | 81.754036ms | localhost:8080 | POST /v1/user
=:-o
from clean-architecture-go-v2.
Answers:
[1] & [2] The database connection has been hijacked by an unrelated MySQL instance.
Improvement Suggestions below.
Details:
API authentication errors continue, despite using the (config sourced) credentials which work interactively in the Docker console shell.
ps aux |grep mysql
# reveals an obsolete mysqld instance, which is stealing the queries to port 3306.
# Note that mysql container in Docker indicates in Docker UI that it has attached to port 3306, yet ...
# Docker log reports (amongst a mass of irrelevant entries): [Note] Aborted connection 8 to db: 'clean_architecture_go_v2' user: 'clean_architecture_go_v2' host: 'localhost' (Got timeout reading communication packets) - not exactly a definitive error :(
brew services stop mysql
# confirm with ps, brew services lis, lanchctl list
In Docker UI restart mysql container.
[6] Next issue: List Users Curl query returns a 500, however the SQL error is more diagnostic:
2022/02/12 11:03:57 In api/handler.user.go/listUsers:26
2022/02/12 11:03:57 ListUsers error: sql: Scan error on column index 0, name "id": Scan: invalid UUID length: 5
[negroni] 2022-02-12T11:03:57+08:00 | 500 | 10.367251ms | localhost:8080 | GET /v1/user
It turns out that the id is not simply varchar(50) as specified in the initdb.sql script. It contains a UUID that is generated at user creation time. So ...
Curl to create a user.
Curl to list users again. Success!
Improvement Suggestions
- 'make test' clearly does no database write/read tests. Add some, even if as a new Make target.
- the /ping route could be upgraded to a /smoketest function that does an ephemeral database connection test.
- MySQL errors are not identified as such - prefix 'Error 1045: Access denied' with a token to indicate message originates from database driver, so it is not mis-perceived as an HTTP auth issue.
- Provide a single paragraph description of the engineering architecture - API code, database, Prometheus, Grafana - what feeds what to what, and where to find the logs!
Onward and Downward ! 😧
from clean-architecture-go-v2.
Related Issues (10)
- Is using `newInmem` only used for testing?
- What does ops folder use for? HOT 2
- user.Validate failing when trying to borrow book (empty Password) HOT 1
- log.Fatal call on main HOT 1
- how to use transaction in clean-arch-go
- Inmem delete() function should consider using delete(r.m, id)
- Clean architecture folder structure HOT 8
- Great job
- Invalid memory access on book validator fail
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clean-architecture-go-v2.