Skip to content

raahii/golang-grpc-realworld-example

Repository files navigation

realworld-logo

Test Status License: MIT GoDoc

Go/GRPC codebase containing RealWorld examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

This codebase was created to demonstrate a fully fledged fullstack application built with golang/grpc including CRUD operations, authentication, routing, pagination, and more.

How it works

figure

  • Using grpc-gateway as reverse-proxy server which translates a RESTful JSON API into gRPC.

  • Using Go to implement realworld backend server.

  • Using MySQL to store data.

Getting started

The app listens and serves on 0.0.0.0:3000.

  • docker-compose

    $ docker-compose up -d
    
  • local

    • Install Go 1.19+, MySQL
    • set environment variables to connect database like this.
    $ go run server.go # run grpc server
    $ go run gateway/gateway.go # run grpc-gateway server
    

Unit test

  • docker-compose

    $ docker-compose run app make unittest
    
  • local

    $ make unittest
    

E2E test

$ make e2etest

TODOs

  • Users and Authentication

    • POST /user/login: Existing user login
    • POST /users: Register a new user
    • GET /user: Get current user
    • PUT /user: Update current user
  • Profiles

    • GET /profiles/{username}: Get a profile
    • POST /profiles/{username}/follow: Follow a user
    • DELETE /profiles/{username}/follow: Unfollow a user
  • Articles

    • GET /articles/feed: Get recent articles from users you follow
    • GET /articles: Get recent articles globally
    • POST /articles : Create an article
    • GET /articles/{slug}: Get an article
    • PUT /articles/{slug}: Update an article
    • DELETE /articles/{slug}: Delete an article
  • Comments

    • GET /articles/{slug}/comments: Get comments for an article
    • POST /articles/{slug}/comments: Create a comment for an article
    • DELETE /articles/{slug}/comments/{id}: Delete a comment for an article
  • Favorites

    • POST /articles/{slug}/favorite: Favorite an article
    • DELETE /articles/{slug}/favorite: Unfavorite an article
  • Deafult

  • GET /tags: Get tags

  • E2E test

    ┌─────────────────────────┬───────────────────┬───────────────────┐
    │                         │          executed │            failed │
    ├─────────────────────────┼───────────────────┼───────────────────┤
    │              iterations │                 1 │                 0 │
    ├─────────────────────────┼───────────────────┼───────────────────┤
    │                requests │                31 │                 0 │
    ├─────────────────────────┼───────────────────┼───────────────────┤
    │            test-scripts │                46 │                 0 │
    ├─────────────────────────┼───────────────────┼───────────────────┤
    │      prerequest-scripts │                17 │                 0 │
    ├─────────────────────────┼───────────────────┼───────────────────┤
    │              assertions │               345 │                 0 │
    ├─────────────────────────┴───────────────────┴───────────────────┤
    │ total run duration: 17.5s                                       │
    ├─────────────────────────────────────────────────────────────────┤
    │ total data received: 8.73KB (approx)                            │
    ├─────────────────────────────────────────────────────────────────┤
    │ average response time: 33ms [min: 10ms, max: 150ms, s.d.: 31ms] │
    └─────────────────────────────────────────────────────────────────┘
    

Releases

No releases published

Packages

No packages published

Languages