This is a simple Go web application that demonstrates user authentication using JSON Web Tokens (JWT) with Gin, PostgreSQL, and GORM.
- User signup and login using JWT.
- Secured endpoint demonstrating JWT authentication middleware.
- Create, Get, Update, Delete Funcions
- Go installed on your machine.
- PostgreSQL database server.
-
Clone the repository:
git clone https://github.com/barkhayot/go-blog.git cd go-blog
-
Install dependencies:
go mod download
-
Set up the PostgreSQL database:
- Create a PostgreSQL database.
- Update the database configuration in the
.env
file.
-
Run the application:
go run main.go
-
POST /signup: Create a new user account.
-
POST /login: Obtain a JWT token by providing valid credentials.
-
GET /posts: Access a posts endpoint by providing a valid JWT token in the Authorization header.
-
GET /posts/:id: Access a posts endpoint by passing ID of needed post
-
POST /posts: Create new post by sending post details in body of request
-
PUT /posts: Update post by ID and sending updated structure in body request
-
DELETE /posts: Delete post by ID
-
The application uses environment variables for configuration. Update the
.env
file with your settings.# Database Configuration DB_HOST=localhost DB_PORT=5432 DB_USER=your_db_user DB_PASSWORD=your_db_password DB_NAME=your_db_name # JWT Configuration SECRET=your_secret_key