Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/say8hi/go-jwt-api
https://github.com/say8hi/go-jwt-api
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/say8hi/go-jwt-api
- Owner: say8hi
- Created: 2024-09-11T18:02:44.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2024-09-13T12:29:00.000Z (2 months ago)
- Last Synced: 2024-09-14T02:38:35.258Z (2 months ago)
- Language: Go
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go JWT API
## Project Structure
The project is organized as follows:
- `cmd/go-jwt-api`: Contains the entry point of the application.
- `internal`: Houses the core logic of the application, including database interactions, handlers, middlewares, and models.
- `tests`: Contains integration tests for the application.
- `Dockerfile` and `docker-compose.yml`: For containerization and orchestration.
- `go.mod` and `go.sum`: Go module files for managing dependencies.## Technologies Used
- **Go**: The primary programming language for building the application.
- **Docker and Docker Compose**: Used for containerizing the application and its services.
- **PostgreSQL**: The database system for storing application data.
- **Gorilla Mux**: A powerful URL router and dispatcher for matching incoming requests to their respective handler.## Setup and Running
To run this project, you need to have Docker and Docker Compose installed on your system. Follow these steps:
1. Clone the repository to your local machine.
```bash
git clone https://github.com/say8hi/go-jwt-api.git
```
2. Go into **go-jwt-api** folder:
```bash
cd go-jwt-api
```
3. Rename `.env.example` to `.env` and adjust the configuration according to your environment.
```bash
mv .env.example .env
```
4. Build and start the services with Docker Compose:
```bash
docker-compose up -d --build
```
This command will start all the required services, including the Go application, PostgreSQL, and RabbitMQ.## API Endpoints
- **Users**
- `POST /users/create`: Create a new user.
- `GET /users/get_tokens?user_id={user_id}`: Create AUTH tokens.
- `POST /users/refresh`: Refresh AUTH tokens.Use the provided `curl` examples in the [Application Usage Examples](#application-usage-examples) section to interact with these endpoints.
## Application Usage Examples
Below are examples of how to interact with the application using `curl`, a command-line tool for transferring data with URLs. These examples demonstrate user creation, category creation, and product creation through the application's API.
### Creating a User
To create a new user, send a POST request with the username and password in JSON format:
```bash
curl -X POST -H "Content-Type: application/json" -d '{"username": "username", "email": "[email protected]"}' http://0.0.0.0:8080/users/create
```## Testing
To run the integration tests:
```bash
./run_tests.sh
```
This script will set up the test environment, run the tests, and tear down the environment afterwards.