blog

command
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 11 Imported by: 0

README

GoFastr Blog Example

A minimal blog application demonstrating JSON entity declarations, CRUD routes, soft delete, custom endpoints, generated OpenAPI, and entity MCP tools.

Quick Start

# From the repository root:
go run examples/blog/main.go

The server starts on http://localhost:8080.

The example uses SQLite at ./blog.db and auto-migrates on startup.

Endpoints

Users
Method Path Auth Description
GET /users No List users
GET /users/{id} No Get user by ID
POST /users Yes Create user
PUT /users/{id} Yes Update user
DELETE /users/{id} Yes Delete user
Posts
Method Path Auth Description
GET /posts No List posts (paginated)
GET /posts/{id} No Get post by ID
GET /posts/published No List published posts only
GET /posts/search?q=... No Search indexed posts
POST /posts Yes Create post
PUT /posts/{id} Yes Update post
DELETE /posts/{id} Yes Soft-delete post
Comments
Method Path Auth Description
GET /comments No List comments
GET /comments/{id} No Get comment by ID
POST /comments Yes Create comment
PUT /comments/{id} Yes Update comment
DELETE /comments/{id} Yes Delete comment
Auth

This example does not enforce auth. Production apps should add auth middleware or per-entity access control before exposing write endpoints.

curl -H "Content-Type: application/json" \
     -d '{"name":"Ada","email":"ada@example.com"}' \
     http://localhost:8080/users
Filtering & Pagination

All list endpoints support query parameters:

GET /posts?page=2&limit=10&sort=-created_at&status=published
Param Example Description
page page=2 Page number (default 1)
limit limit=10 Items per page (max 100)
sort sort=-title Sort field (- for descending)
{field} status=draft Exact-match filter
{field}_like title_like=go Contains filter

Entities & Relationships

User ──< Post ──< Comment
  • User has many Posts and Comments (via author_id)
  • Post belongs to User (author), has many Comments, and supports soft-delete
  • Comment belongs to both Post and User

JSON Declarations

The entities are declared in examples/blog/entities/*.json. This format is designed for AI code generation: describe your entities and the framework builds the routes, migrations, OpenAPI schemas, and MCP CRUD tools.

{
  "name": "posts",
  "soft_delete": true,
  "fields": [
    { "name": "title", "type": "string", "required": true },
    { "name": "body", "type": "text" },
    { "name": "status", "type": "enum", "values": ["draft", "published"] }
  ],
  "crud": true,
  "mcp": true
}

Generate Go from those declarations:

cd examples/blog
gofastr generate

The blog uses battery/search with the in-memory backend for /posts/search. Production apps can swap this interface for a Postgres full-text, Meilisearch, or Elasticsearch backend.

MCP Tools

Each entity sets "mcp": true, so GoFastr registers CRUD tools:

Tool Description Parameters
posts_list List posts filters, page, limit
posts_get Get a post id
posts_create Create a post writable post fields
posts_update Update a post id + writable fields
posts_delete Delete a post id

The same pattern exists for users and comments.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL