Skip to content

Commit 9719b76

Browse files
committed
impr adds readme.md adds health check endpoint to '/'
1 parent 7465876 commit 9719b76

File tree

2 files changed

+198
-0
lines changed

2 files changed

+198
-0
lines changed

README.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
2+
# GRPC-CRUD
3+
4+
A simple user management service built using Golang, ScyllaDB, gRPC and served through HTTP using gRPC-gateway. This service provides a RESTful API interface that proxies HTTP requests to compatible gRPC actions.
5+
6+
7+
## Tech Stack
8+
9+
- **Go**: Primary programming language
10+
- **gRPC**: High-performance RPC framework
11+
- **gRPC-Gateway**: Proxies HTTP APIs to gRPC
12+
- **Protocol Buffers**: Interface definition language
13+
- **ScyllaDB**: Performant NoSQL database
14+
- **docker**/**docker-compose**: Containerization and environment setup
15+
- **GitHub Actions**: CI/CD pipeline for auto deployment
16+
- **Buf**: Protocol buffer compiler and dependency management
17+
18+
19+
## Project Structure
20+
21+
```
22+
.
23+
├── buf.gen.yaml
24+
├── buf.lock
25+
├── buf.yaml
26+
├── compose.yaml
27+
├── Dockerfile
28+
├── go.mod
29+
├── go.sum
30+
├── main.go
31+
├── proto
32+
│ └── users
33+
│ ├── users_grpc.pb.go
34+
│ ├── users.pb.go
35+
│ ├── users.pb.gw.go
36+
│ └── users.proto
37+
├── README.md
38+
├── src
39+
│ ├── db
40+
│ │ └── db.go
41+
│ ├── models
42+
│ │ └── User.go
43+
│ └── services
44+
│ └── userService.go
45+
```
46+
47+
48+
## Prerequisites
49+
50+
- Go 1.23.0 or later
51+
- Docker and Docker Compose
52+
- Buf CLI
53+
- Git
54+
55+
56+
## Setup and Installation
57+
58+
### 1. Clone the Repository
59+
60+
```bash
61+
git clone https://github.com/2k4sm/grpc-crud.git
62+
cd grpc-crud
63+
```
64+
65+
66+
### 2. Start ScyllaDB with Docker Compose
67+
68+
#### Set env variables into `.env`.
69+
```bash
70+
touch .env
71+
echo "SDB_URI=localhost" >> .env
72+
```
73+
Then run
74+
```bash
75+
docker-compose up -d
76+
```
77+
78+
79+
This will start a ScyllaDB instance as defined in the `compose.yaml` file.
80+
81+
### 3. Install Dependencies
82+
83+
```bash
84+
go mod download
85+
```
86+
87+
88+
### 4. Generate Protocol Buffer Code
89+
90+
```bash
91+
buf generate
92+
```
93+
94+
95+
### 5. Build and Run the Application
96+
97+
```bash
98+
go build -o grpc-crud .
99+
./grpc-crud
100+
```
101+
102+
Alternatively, you can use:
103+
104+
```bash
105+
go run main.go
106+
```
107+
108+
### Deployment to EC2
109+
110+
This is configured for automatic deployment to EC2 using GitHub Actions. When changes are pushed to the main branch, the CI/CD pipeline will:
111+
112+
1. Build the application
113+
2. Deploy to the EC2 instance
114+
115+
### Deployed URL: https://grpc-crud.2k4sm.tech
116+
117+
## HTTP Endpoints
118+
- GET /users?email={email}: Get a user by email
119+
120+
```bash
121+
curl -X GET "http://localhost:8080/[email protected]"
122+
```
123+
124+
or
125+
126+
```bash
127+
curl -X GET "http://localhost:8080/users?ph_number=1234567890"
128+
```
129+
- POST /users: Create a new user
130+
131+
```bash
132+
curl -X POST http://localhost:8080/users \
133+
-H "Content-Type: application/json" \
134+
-d '{
135+
"first_name": "John",
136+
"last_name": "Doe",
137+
"gender": "MALE",
138+
"dob": "1990-01-01",
139+
"ph_number": "1234567890",
140+
"email": "[email protected]",
141+
"access": "UNBLOCKED"
142+
}'
143+
```
144+
- PUT /users/{email}: Update a user by email
145+
146+
```bash
147+
curl -X PUT http://localhost:8080/users/[email protected] \
148+
-H "Content-Type: application/json" \
149+
-d '{
150+
"first_name": "John",
151+
"last_name": "Doe",
152+
"gender": "MALE",
153+
"dob": "1990-01-01",
154+
"ph_number": "0987654321",
155+
"email": "[email protected]",
156+
}'
157+
```
158+
- PATCH /users/{curr_email}: Update a user's email or phone number
159+
160+
```bash
161+
curl -X PATCH http://localhost:8080/users/[email protected] \
162+
-H "Content-Type: application/json" \
163+
-d '{
164+
"new_email": "[email protected]",
165+
"new_ph_number": "1122334455"
166+
}'
167+
```
168+
- POST /users/{email}/block: Block a user
169+
170+
```bash
171+
curl -X POST http://localhost:8080/users/[email protected]/block
172+
```
173+
- POST /users/{email}/unblock: Unblock a user
174+
175+
```bash
176+
curl -X POST http://localhost:8080/users/[email protected]/unblock
177+
```
178+
179+
# Thank You for trying out grpc-crud.

main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"log"
67
"net"
78
"net/http"
9+
"time"
810

911
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
1012
"github.com/joho/godotenv"
@@ -49,6 +51,23 @@ func main() {
4951
}
5052

5153
mux := runtime.NewServeMux()
54+
mux.HandlePath("GET", "/", func(w http.ResponseWriter, r *http.Request, _ map[string]string) {
55+
w.Header().Set("Content-Type", "application/json")
56+
w.WriteHeader(http.StatusOK)
57+
58+
response := struct {
59+
Time string `json:"time"`
60+
Message string `json:"message"`
61+
}{
62+
Time: time.Now().Format(time.RFC3339),
63+
Message: "healthy",
64+
}
65+
66+
if err := json.NewEncoder(w).Encode(response); err != nil {
67+
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
68+
}
69+
})
70+
5271
err = userspb.RegisterUsersHandler(context.Background(), mux, conn)
5372
if err != nil {
5473
log.Fatalln("Failed to register gateway:", err)

0 commit comments

Comments
 (0)