This is a user management API built with Go. It provides endpoints for registering, logging in, managing and logging out users.
- User registration: Allows users to create an account with a username, email, and password.
- User login: Provides a way for users to log in to the API.
- User retrieval: Allows retrieving information about a specific user.
- User deletion: Provides a way to delete a user.
- User logout: Provides a way for users to log out of the API and blacklist the token.
- Gin (Web Framework): Gin is a high-performance web framework for Go that provides routing, middleware, and more to build web applications.
- GORM (ORM): GORM is an Object-Relational Mapping library for Go that simplifies database interactions by providing a higher-level abstraction over SQL queries.
- golang-jwt v5 (JWT implementation): golang-jwt v5 is a module for implementing JSON Web Tokens (JWT) in Go, providing functionality for creating, validating, and parsing JWTs.
-
Clone the repository:
git clone https://github.com/oscar503sv/gin-jwt.git
-
Install dependencies:
go mod download
-
Set up the database:
- Create a SQLite database file named
user.db
. You can configure any database engine in thedatabase.go
file. - Run the
config.ConnectDB()
function to connect to the database.
-
Run the API:
go run main.go
-
Make API requests:
- Use a tool like cURL or Postman to send HTTP requests to the API endpoints.
- The API endpoints are as follows:
- Register a user:
POST /register
- Login:
POST /login
- Logout:
POST /logout
- Retrieve all users:
GET /users
- Retrieve a user:
GET /users/{id}
- Update a user:
PUT /users/{id}
- Delete a user:
DELETE /users/{id}
- Register a user:
- If you want to contribute a new feature or improve the current implementation, please open an issue first.
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
Oscar's website.