Skip to content

ndy2/realworld-gin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

realworld-gin

logo

coverage

Built with

Go Copilot Gin MySQL Zap

Auth/User

  • Authentication
    • Endpoint
    • JWT
  • Register
    • Endpoint
    • Insert Profile to DB
  • Get current user
  • Update

Profile

  • Get Profile
    • Current User Profile (authenticated)
    • Other User Profile (authenticated)
      • check Followed by current user
    • arbitrary User Profile (unauthenticated)
  • Update User (Profile)

Follow

  • Follow User
  • Unfollow User

Article

  • List Articles
  • Feed Articles
  • Get Article
  • Create Article
  • Update Article
  • Delete Article

Comments

  • Add Comments to an Article
  • Get Comments from an Article
  • Delete Comment

Favorites

  • Favorite Article
  • Unfavorite Article

Tags

  • Get Tags

Common

  • 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)
  • Documentation - SKIP FOR NOW
    • about Project (w/ mkdocs-material)
    • about API (w/ Swagger) - SKIP FOR NOW
  • Logging (w/ Zap)

Scripts

Run the app

go run cmd/realworld/main.go

Run tests

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

Run Integration Tests

# 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

Create go mock for xxxapp#Logic interfaces

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published