-
Clone the Repository:
git clone https://github.com/wisamidris7/template-backend.git cd template-backend
-
Install Dependencies:
go mod tidy
-
Run the Server:
go run main.go
The entry point of the application. It initializes the database connection, sets up the router, and starts the server.
// filepath: /C:/Users/wisam/Desktop/template/backend/main.go
// ...existing code...
Contains the logic for connecting to the database and running migrations.
// filepath: /C:/Users/wisam/Desktop/template/backend/config/database.go
// ...existing code...
Seeds the database with initial data.
// filepath: /C:/Users/wisam/Desktop/template/backend/config/seeder.go
// ...existing code...
Defines the User model and its methods for password hashing and validation.
// filepath: /c:/Users/wisam/Desktop/template/backend/models/user.go
// ...existing code...
Sets up the main application routes and middleware.
// filepath: /c:/Users/wisam/Desktop/template/backend/router/router.go
// ...existing code...
Defines the data transfer object for the User model.
// filepath: /c:/Users/wisam/Desktop/template/backend/router/dtos/userDto.go
// ...existing code...
Sets up the authentication routes.
// filepath: /c:/Users/wisam/Desktop/template/backend/auth/router.go
// ...existing code...
Defines the request and response models for authentication.
// filepath: /c:/Users/wisam/Desktop/template/backend/auth/models.go
// ...existing code...
Contains the logic for generating and validating JWT tokens and the authentication middleware.
// filepath: /c:/Users/wisam/Desktop/template/backend/auth/auth_jwt.go
// ...existing code...
-
Start the Server:
go run main.go
-
Access the Application: Open your browser and navigate to
http://127.0.0.1:8080
.
GET /api/users
: Fetch all users.POST /api/users
: Create a new user.
POST /auth/login
: Login and receive a JWT token.
Feel free to contribute and improve the code. Fork the repository, make your changes, and submit a pull request.
This is my first app made in Go, so don't blame me if there is anything bad or wrong.