Skip to content

Commit b943a7f

Browse files
resolved merge conflicts
2 parents 134baa5 + 9668296 commit b943a7f

49 files changed

Lines changed: 1290 additions & 67 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@khareyash05
1+
* @khareyash05

.github/workflows/golangci-lint.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
- fasthttp-postgres
3232
- gin-mongo
3333
- gin-redis
34+
- go-grpc
3435
- go-jwt
3536
- go-twilio
3637
- graphql-sql
@@ -41,26 +42,24 @@ jobs:
4142
- S3-Keploy
4243
- sse-svelte
4344
- users-profile
45+
- book-store-inventory
4446

4547
steps:
4648
- uses: actions/checkout@v3
4749
- uses: actions/setup-go@v4
4850
with:
49-
go-version: '1.21'
51+
go-version: '1.23.4'
5052
cache: false
5153
- name: golangci-lint
5254
uses: golangci/golangci-lint-action@v3
5355
with:
5456
# Require: The version of golangci-lint to use.
5557
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
5658
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
57-
version: v1.54
59+
version: v1.63.4
5860

5961
# Optional: working directory, useful for monorepos
6062
working-directory: ${{matrix.working-directory}}
6163

62-
# Optional: show only new issues if it's a pull request. The default value is `false`.
63-
only-new-issues: true
64-
6564
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
6665
install-mode: "goinstall"

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,24 @@ This repo contains the sample for [Keploy's](https://keploy.io)🐰 with Golang.
1818

1919
## Go Sample Apps with Keploy
2020

21-
1. [Echo-SQL](https://github.com/keploy/samples-go/tree/main/echo-sql)
22-
2. [Fasthttp-Postgress](https://github.com/sarthaksarthak9/samples-go/tree/main/fasthttp-postgres)
23-
3. [Gin-Mongo](https://github.com/keploy/samples-go/tree/main/gin-mongo)
24-
4. [Gin-Redis](https://github.com/sarthaksarthak9/samples-go/tree/main/gin-redis)
25-
5. [GraphQL-SQL](https://github.com/keploy/samples-go/tree/main/graphql-sql)
26-
6. [Mux-SQL](https://github.com/keploy/samples-go/tree/main/mux-sql)
27-
7. [S3-Keploy](https://github.com/sarthaksarthak9/samples-go/tree/main/S3-Keploy)
28-
8. [SSE-Svelte](https://github.com/sarthaksarthak9/samples-go/tree/main/sse-svelte)
29-
9. [Users-Profile](https://github.com/keploy/samples-go/tree/main/users-profile)
21+
1. [Echo-MySQL](https://github.com/keploy/samples-go/tree/main/echo-mysql)
22+
2. [Echo-SQL](https://github.com/keploy/samples-go/tree/main/echo-sql)
23+
3. [Fasthttp-Postgress](https://github.com/keploy/samples-go/tree/main/fasthttp-postgres)
24+
4. [Gin-Mongo](https://github.com/keploy/samples-go/tree/main/gin-mongo)
25+
5. [Gin-Redis](https://github.com/keploy/samples-go/tree/main/gin-redis)
26+
6. [Go-Grpc](https://github.com/keploy/samples-go/tree/main/go-grpc)
27+
7. [Go-Jwt](https://github.com/keploy/samples-go/tree/main/go-jwt)
28+
8. [Go-Twilio](https://github.com/keploy/samples-go/tree/main/go-twilio)
29+
9. [GraphQL-SQL](https://github.com/keploy/samples-go/tree/main/graphql-sql)
30+
10. [Mux-SQL](https://github.com/keploy/samples-go/tree/main/mux-sql)
31+
11. [Mux-Elasticsearch](https://github.com/keploy/samples-go/tree/main/mux-elasticsearch)
32+
12. [Mux-MySQL](https://github.com/keploy/samples-go/tree/main/mux-mysql)
33+
13. [S3-Keploy](https://github.com/keploy/samples-go/tree/main/S3-Keploy)
34+
14. [SSE-Svelte](https://github.com/keploy/samples-go/tree/main/sse-svelte)
35+
15. [Users-Profile](https://github.com/keploy/samples-go/tree/main/users-profile)
36+
16. [HTTP-PokeAPI](https://github.com/keploy/samples-go/tree/main/http-pokeapi)
37+
17. [book-store-inventory (`gin + sqlite`) ](https://github.com/keploy/samples-go/tree/main/book-store-inventory)
38+
3039

3140
## Community Support ❤️
3241

book-store-inventory/.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Binaries and build artifacts
2+
/book-store-inventory
3+
/tmp/
4+
*.exe
5+
*.out
6+
*.test
7+
8+
# Logs and debugging files
9+
*.log
10+
*.trace
11+
12+
# Environment and config files
13+
.env
14+
config.yaml
15+
16+
# Go module files (optional, but recommended for clean repo)
17+
# /go.sum
18+
19+
# Compiled Python files (if any scripts are used)
20+
__pycache__/
21+
*.pyc
22+
*.pyo
23+
*.pyd
24+
25+
# OS-specific files
26+
.DS_Store
27+
Thumbs.db
28+
29+
# Editor and IDE-specific files
30+
.vscode/
31+
.idea/
32+
*.iml
20 KB
Binary file not shown.

book-store-inventory/README.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
<div align="center">
2+
<!-- <img src="./images/api_logo.png" alt="API Logo" width="80" height="80"/> -->
3+
</div>
4+
5+
<h1 align="center">Book Store Inventory</h1>
6+
7+
<div align="center">
8+
<img src="https://img.shields.io/badge/Sample%20Project%20for%20-Keploy%20-ea580c?style=for-the-badge" alt="Showcase Project">
9+
<br>
10+
<img src="https://img.shields.io/badge/License-MIT-ed8796.svg?style=for-the-badge" alt="MIT License">
11+
</div>
12+
<br>
13+
14+
A simple book store inventory backend built using the Gin framework and SQLite as the database.
15+
16+
## :computer: Tech Stack
17+
- [**Go**](https://go.dev/) : Programming language
18+
- [**Gin**](https://github.com/gin-gonic/gin) : Web framework
19+
- [**SQLite3**](https://github.com/mattn/go-sqlite3) : A sqlite3 database driver
20+
21+
<br>
22+
23+
## :book: How to Use / Run on Your Machine
24+
25+
- ### Prerequisites:
26+
- Install Go (version >= 1.23.3): https://golang.org/dl/
27+
- API Testing Tool
28+
- [Postman](https://www.postman.com/downloads/)
29+
- [Httpie](https://httpie.io/download)
30+
31+
> I am using [**HttPie**](https://httpie.io/download) for API testing
32+
> you can use any tool as per your requirement
33+
> and `curl` is fine too :D
34+
35+
> [!IMPORTANT]
36+
> I am using WSL (Ubuntu). I recommend using Linux/WSL or macOS.
37+
38+
<br>
39+
40+
### :package: Keploy Installation
41+
for detailed installation info visit
42+
https://keploy.io/docs/server/installation/#keploy-installation
43+
44+
```sh
45+
curl --silent -O -L https://keploy.io/install.sh && source install.sh
46+
```
47+
48+
<br>
49+
50+
### :toolbox: Setup Project Locally:
51+
52+
- Clone the repository:
53+
```sh
54+
git clone https://github.com/keploy/samples-go.git
55+
```
56+
57+
- Navigate to the project directory:
58+
```sh
59+
cd book-store-inventory
60+
```
61+
62+
- Install dependencies:
63+
```sh
64+
go mod download
65+
```
66+
- Generate Database with some default data:
67+
68+
> [!IMPORTANT]
69+
>
70+
> `OPTIONAL STEP` as I have already included the `book_inventory.db`
71+
>
72+
> delete the `book_inventory.db` in `DB/book_inventory.db` and use below command to generate new one
73+
74+
```sh
75+
go run migrations/migration.go
76+
```
77+
78+
- Building the Application Binary:
79+
```sh
80+
go build
81+
```
82+
83+
> :rocket: You're all set! Now you have `book-store-inventory`
84+
85+
86+
<br>
87+
88+
### :inbox_tray: Capture the test cases using Keploy
89+
90+
```sh
91+
sudo -E keploy record -c "./book-store-inventory
92+
```
93+
> [!TIP]
94+
> If any error occur try above command without `sudo -E`
95+
96+
97+
<br>
98+
99+
### :satellite: Open the Postman/Httpie and Make Request
100+
101+
<div align="center">
102+
<img src="./docs/assets/all_books.png" alt="GET" style="width: 48%;">
103+
<img src="./docs/assets/book_by_id.png" alt="READ" style="width: 48%;">
104+
</div>
105+
106+
<div align="center">
107+
<img src="./docs/assets/add_book.png" alt="PUT" style="width: 48%;">
108+
<img src="./docs/assets/delete_book.png" alt="DELETE" style="width: 48%;">
109+
</div>
110+
111+
<br>
112+
113+
### :bookmark_tabs: Available REST API End Points
114+
115+
| Method | Endpoint | Description |
116+
|---------|-------------------------------------------------------|---------------------------------|
117+
| **GET** | `http://localhost:9090/api/v1/books/` | Get all books |
118+
| **GET** | `http://localhost:9090/api/v1/book/id/:book_id` | Get a book by ID |
119+
| **POST** | `http://localhost:9090/api/v1/book/add/` | Add a new book |
120+
| **DELETE** | `http://localhost:9090/api/v1/book/delete/` | Delete a book |
121+
| **PATCH** | `http://localhost:9090/api/v1/book/update/` | Update a book |
122+
| **GET** | `http://localhost:9090/api/test-api` | Test API (New Endpoint) |
123+
124+
125+
<br>
126+
127+
> [!TIP]
128+
>
129+
> for now just call `GET` for `http://localhost:9090/api/v1/books/`
130+
>
131+
> and record this test
132+
133+
<br>
134+
135+
### :jigsaw: Usage Examples
136+
137+
> [!IMPORTANT]
138+
> Add these json value as body while making request
139+
140+
- #### POST (Add New Book)
141+
142+
body of the request
143+
```json
144+
{
145+
"title": "Gunaho ka Devta",
146+
"author": "Dharamvir Bharti",
147+
"price": 599.99,
148+
"published_date": "1949-01-01T00:00:00Z",
149+
"stock_quantity": 5
150+
}
151+
```
152+
153+
- #### DELETE (Delete Book by ID)
154+
155+
body of the request
156+
```json
157+
{
158+
"book_id": 6
159+
}
160+
```
161+
162+
- #### PATCH (Update Book by ID)
163+
164+
body of the request
165+
```json
166+
{
167+
"book_id": 6,
168+
"title": "Gunaho ka God (latest edition)",
169+
"author": "Dharamvir Bharti Ji",
170+
"price": 599.99,
171+
"published_date": "1949-01-01T00:00:00Z",
172+
"stock_quantity": 5
173+
}
174+
```
175+
176+
<div align="center">
177+
<img src="./docs/assets/keploy_test_capture.png" alt="TEST API">
178+
</div>
179+
180+
<br>
181+
182+
### :test_tube: Run the captured test case
183+
184+
> [!IMPORTANT]
185+
> Stop the test capturing by pressing `ctrl+c` or `ctrl+z`
186+
187+
start the test using keploy
188+
```sh
189+
sudo -E keploy test -c "./book-store-inventory" --delay 1
190+
```
191+
192+
<div align="center">
193+
<img src="./docs/assets/keploy_test_run_1.png" alt="PUT" style="width: 48%;">
194+
<img src="./docs/assets/keploy_test_run_2.png" alt="DELETE" style="width: 48%;">
195+
</div>
196+
197+
<br>
198+
199+
## :seedling: Todo / Future Improvements
200+
- [x] Show All Books Data
201+
- [x] Get Particular Book By ID
202+
- [x] Add New Book Data
203+
- [x] Delete Book Data
204+
- [x] Update Book Data
205+
- [ ] UI for this Application (NextJS/Vite-React)
206+
207+
208+
## :compass: About
209+
This project was created as a sample to understand the working of Keploy.
111 KB
Loading
133 KB
Loading
85.8 KB
Loading
82.3 KB
Loading

0 commit comments

Comments
 (0)