A Go-based content handler service for WordPress automation with Ollama integration (local LLM).
- Go 1.21+ - Download
- Docker & Docker Compose (optional but recommended)
- Ollama - Download
- WordPress instance with REST API enabled
- Pixabay API key - Get free key
- Copy environment template:
cp .env.example .env- Edit .env with your credentials:
WORDPRESS_URL=https://your-wordpress-site.com
WORDPRESS_USERNAME=your_username
WORDPRESS_PASSWORD=your_password
PIXABAY_API_KEY=your_key
OLLAMA_URL=http://localhost:11434
OLLAMA_MODEL=mistral- Run setup or installation:
go mod tidy
go run main.gogo run main.goServer runs at http://localhost:8080
docker-compose updocker build -t dc-handler:latest --target production .
docker run -p 8080:8080 --env-file .env dc-handler:latest.
├── main.go # Entry point
├── go.mod / go.sum # Dependencies
├── docker-compose.yml # Development container
├── Dockerfile # Multi-stage build
├── .env.example # Environment template
│
├── config/
│ └── config.go # Configuration loading
├── handlers/
│ ├── wp_posts.go # GET /api/wp-posts
│ ├── optimize_content.go # POST /api/optimize-content
│ └── publish_post.go # POST /api/publish-post
├── services/
│ ├── wordpress.go # WordPress API
│ ├── pixabay.go # Image search
│ └── ollama.go # Local LLM
└── utils/
└── auth.go # Auth helpers
Fetch WordPress posts
Query: ?status=draft&per_page=100
Response:
{
"success": true,
"posts": [{"id": 123, "title": "Post", "content": "..."}]
}Optimize content using Ollama
Body:
{
"title": "Title",
"content": "Content",
"excerpt": "Excerpt"
}Response:
{
"optimizedTitle": "Optimized Title",
"optimizedContent": "Optimized content from Ollama",
"suggestedImage": "https://pixabay.com/image.jpg",
"imageSource": "Pixabay"
}Publish post to WordPress
Body:
{
"postId": 123,
"title": "Title",
"content": "Content",
"featuredImageUrl": "https://example.com/image.jpg"
}| Variable | Default | Description |
|---|---|---|
PORT |
8080 | Server port |
ENV |
development | Environment mode |
WORDPRESS_URL |
- | WordPress URL |
WORDPRESS_USERNAME |
- | WordPress username |
WORDPRESS_PASSWORD |
- | WordPress password |
OLLAMA_URL |
http://localhost:11434 | Ollama server |
OLLAMA_MODEL |
mistral | Model to use |
PIXABAY_API_KEY |
- | Pixabay API key |
# 1. Setup
cp .env.example .env
# Edit .env with credentials
# 2. Download dependencies
go mod download
# 3. Start Ollama (in another terminal)
ollama serve
# 4. Run application
go run main.go
# 5. Test endpoints
curl http://localhost:8080/api/wp-postscurl http://localhost:8080/healthMIT