90%70%60% of the code is written by Github Copilot... I just modified it a bit.- see https://realworld-docs.netlify.app/specifications/backend/endpoints/
Built with
- Authentication
- Endpoint
- JWT
- Register
- Endpoint
- Insert Profile to DB
- Get current user
- Update
- Get Profile
- Current User Profile (authenticated)
- Other User Profile (authenticated)
- check Followed by current user
- arbitrary User Profile (unauthenticated)
- Update User (Profile)
- Follow User
- Unfollow User
- List Articles
- Feed Articles
- Get Article
- Create Article
- Update Article
- Delete Article
- Add Comments to an Article
- Get Comments from an Article
- Delete Comment
- Favorite Article
- Unfavorite Article
- Get Tags
- Authentication
- Required
- Optional
- Json Marshal/Unmarshal
- on success (single response)
- on success (list response)
- on error (Error handling)
- Input Validation
- Package structure - I'm satisfied with the current structure!
- Configuration
- internal/config
-
more sophisticated configuration- SKIP FOR NOW
- Concurrent Logic with Goroutine (w/ ErrGroup)
- Infrastructure (Database)
- Database Setup (w/ MySQL, Docker)
-
Connection Pool- Go has built-in connection pooling -
Transaction- SKIP FOR NOW - Use SQLX
- Testing
- Unit Tests Samples (w/ go-mock, go-cmp)
- middleware
- route (w/ httptest)
- handler
- logic
- repo (w/ sqlmock)
- GitHub Actions - Run tests on push
- Unit Tests
- Integration Test (w/ newman/docker-compose)
- Unit Tests Samples (w/ go-mock, go-cmp)
-
Documentation- SKIP FOR NOW- about Project (w/ mkdocs-material)
-
about API (w/ Swagger)- SKIP FOR NOW
- Logging (w/ Zap)
go run cmd/realworld/main.go
run all tests
go test ./...
create coverage report
go test -coverprofile=test.coverage.tmp -coverpkg=$(go list ./... | paste -sd ',' -) ./... && cat test.coverage.tmp | grep -v 'mock' > test.coverage && go tool cover -func test.coverage
go tool cover -html=test.coverage -o coverage.html
# start the database
cd resources/database && docker-compose up -d
sleep 10 # wait for the database to be ready
# run the tests
cd ../postman && ./run-api-tests.sh
packages=("auth" "profile" "user")
for pkg in "${packages[@]}"; do
mockgen -source=internal/${pkg}/app/logic.go -destination=internal/${pkg}/app/logic_mock.go -package=app
mockgen -source=internal/${pkg}/domain/domain.go -destination=internal/${pkg}/domain/mock_repo.go -package=domain
done