A simple Go-based microservice that provides CRUD operations for messages and includes palindrome detection functionality.
messages-service/
├── database
├── db_connection_test.go
├── db_connection.go
├── models.go
└── schema.sql
├── handlers
├── handlers.go
└── handlers_test.go
├── utils
├── palindrome.go
└── palindrome_test.go
├── go.mod
├── go.sum
├── main.go
└── main_test.go
- Go (version 1.17 or higher)
- Docker
- PostgreSQL
-
Clone the repository
git clone https://github.com/shawn1912/messages-service.git cd messages-service
-
Set up the database
Ensure PostgreSQL is running and create the
messages
database.psql -U postgres CREATE DATABASE messages; \q
Run the schema script:
psql -U postgres -d messages -f ./database/schema.sql
-
Run the application
go run .
POST /message
: Create a new message.GET /messages
: List messages (max 100).GET /message/{id}
: Retrieve a message.PUT /message/{id}
: Update a message.DELETE /message/{id}
: Delete a message.
curl -X POST http://localhost:8080/messages \
-H 'Content-Type: application/json' \
-d '{"content": "A man a plan a canal Panama"}'
{
"id": 29,
"content": "A man a plan a canal Panama",
"isPalindrome": true,
"createdAt": "2024-10-28T12:00:00Z",
"updatedAt": "2024-10-28T12:00:00Z"
}
Run unit tests:
go test ./...