Skip to content

Commit

Permalink
added auth scaffold and protecting route
Browse files Browse the repository at this point in the history
  • Loading branch information
JubaerHossain committed Jul 11, 2024
1 parent 255a529 commit 20489fa
Show file tree
Hide file tree
Showing 16 changed files with 698 additions and 126 deletions.
163 changes: 121 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ A CLI tool for building RESTful APIs with Go

Select an option:
1. Create Module
2. Create Migration
3. Create Seeder
4. Create Migration with Seeder
5. Apply Migrations
6. Run Seeders
7. Run API Docs
0. Return to Main Menu
2. Create Module with run
3. Create Migration
4. Create Seeder
5. Create Migration with Seeder
6. Apply Migrations
7. Run Seeders
8. Scaffold Auth
9. Run API Docs
0. Exit
Enter the command number: 1
Enter module name: users
```
Expand All @@ -76,13 +78,15 @@ A CLI tool for building RESTful APIs with Go

Select an option:
1. Create Module
2. Create Migration
3. Create Seeder
4. Create Migration with Seeder
5. Apply Migrations
6. Run Seeders
7. Run API Docs
0. Return to Main Menu
2. Create Module with run
3. Create Migration
4. Create Seeder
5. Create Migration with Seeder
6. Apply Migrations
7. Run Seeders
8. Scaffold Auth
9. Run API Docs
0. Exit
Enter the command number: 2
Enter migration name: users
```
Expand All @@ -98,13 +102,15 @@ A CLI tool for building RESTful APIs with Go

Select an option:
1. Create Module
2. Create Migration
3. Create Seeder
4. Create Migration with Seeder
5. Apply Migrations
6. Run Seeders
7. Run API Docs
0. Return to Main Menu
2. Create Module with run
3. Create Migration
4. Create Seeder
5. Create Migration with Seeder
6. Apply Migrations
7. Run Seeders
8. Scaffold Auth
9. Run API Docs
0. Exit
Enter the command number: 3
Enter migration name: users
```
Expand All @@ -120,13 +126,15 @@ A CLI tool for building RESTful APIs with Go

Select an option:
1. Create Module
2. Create Migration
3. Create Seeder
4. Create Migration with Seeder
5. Apply Migrations
6. Run Seeders
7. Run API Docs
0. Return to Main Menu
2. Create Module with run
3. Create Migration
4. Create Seeder
5. Create Migration with Seeder
6. Apply Migrations
7. Run Seeders
8. Scaffold Auth
9. Run API Docs
0. Exit
Enter the command number: 4
Enter migration name: users
```
Expand All @@ -143,13 +151,15 @@ A CLI tool for building RESTful APIs with Go

Select an option:
1. Create Module
2. Create Migration
3. Create Seeder
4. Create Migration with Seeder
5. Apply Migrations
6. Run Seeders
7. Run API Docs
0. Return to Main Menu
2. Create Module with run
3. Create Migration
4. Create Seeder
5. Create Migration with Seeder
6. Apply Migrations
7. Run Seeders
8. Scaffold Auth
9. Run API Docs
0. Exit
Enter the command number: 5
Applying migrations...
Enter database user: postgres
Expand All @@ -172,13 +182,15 @@ A CLI tool for building RESTful APIs with Go

Select an option:
1. Create Module
2. Create Migration
3. Create Seeder
4. Create Migration with Seeder
5. Apply Migrations
6. Run Seeders
7. Run API Docs
0. Return to Main Menu
2. Create Module with run
3. Create Migration
4. Create Seeder
5. Create Migration with Seeder
6. Apply Migrations
7. Run Seeders
8. Scaffold Auth
9. Run API Docs
0. Exit
Enter the command number: 6
Applying migrations...
Enter database user: postgres
Expand Down Expand Up @@ -211,6 +223,73 @@ func setupRoutes(application *app.App) http.Handler {


}
```

### File upload documentation

- Add the following code in your codebase
- Here **image** is the name of the form field and **foods** is the folder name
- The uploaded file will be saved in the **uploads/foods** folder
- You can use **local storage** or can use **S3 AWS**
- set the following environment variable in the .env file
```bash
STORAGE_DISK=local // s3
STORAGE_PATH=storage
AWS_ACCESS_KEY=
AWS_SECRET_KEY=
AWS_REGION=ap-southeast-1
AWS_BUCKET=aws-bucket
AWS_ENDPOINT=https://s3.ap-southeast-1.amazonaws.com
```
- Example:

```bash
imageMetadata, err := r.app.FileUpload.FileUpload(req, "image", "foods") // "image" is the name of the form field and "foods" is the folder name
if err != nil {
return fmt.Errorf("failed to upload image: %v", err)
}
```
### Create Auth Scaffold
- Example:
```bash
go run ./cmd/rootx
```
```bash
Select an option:
1. Create Module
2. Create Module with run
3. Create Migration
4. Create Seeder
5. Create Migration with Seeder
6. Apply Migrations
7. Run Seeders
8. Scaffold Auth
9. Run API Docs
0. Exit
Enter the command number: 8
```
### Auth
- Add the following code in your route.go
- will protected the routes
- Example :
```bash
router.Handle("GET /employees", middleware.LimiterMiddleware(middleware.AuthMiddleware(http.HandlerFunc(handler.GetEmployees))))
```
### Database Connection
- Added postgres and mysql database connection
- By default, it will connect to the postgres database
- You can change the database connection by changing the database connection in .env file
- Example:
```bash
DB_TYPE=postgres // or mysql
DB_HOST=db_host
DB_PORT=db_port
DB_NAME=db_name
DB_USER=db_user
DB_PASSWORD=db_password
```
#### run the following command
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ require (

require (
github.com/go-playground/validator/v10 v10.18.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/joho/godotenv v1.5.1
github.com/prometheus/client_golang v1.18.0
go.uber.org/zap v1.26.0
Expand Down
Loading

0 comments on commit 20489fa

Please sign in to comment.