How zifrit/gomicroblog works
MicroBlog is a small in-memory Go REST service for registering users, publishing and listing posts, and asynchronously applying likes. Requests enter through the HTTP server and handlers, which call the service or submit validated like jobs; a worker applies queued likes. The service maintains synchronized state and publishes events to an asynchronous stdout logger. The README also documents Go pprof. Runtime wiring is shown from the sampled entry point; peripheral implementation details are omitted.
Main entry points: service.go Blog service · main.go HTTP server · register_handler.go API routes · logger.go Event logger
Components 15
Runtime wiring
- HTTP server
cmd/main.go - pprof endpoint
cmd/main.go
HTTP API
- API routes
internal/handlers/register_handler.go - User registration
internal/handlers/register_handler.go - Post endpoints
internal/handlers/posts_handler.go - Like endpoint
internal/handlers/like_handler.go
Blog domain
- Blog service
internal/service/service.go - In-memory state
internal/service/service.go - User and post
internal/models/models.go - Post ID counter
internal/syncutils/counter.go
Async operations
- Like queue
internal/queue/like_queue.go - Like worker
internal/queue/like_queue.go - Event logger
internal/logger/logger.go
Other components
- HTTP client
- stdout
Connections 22
- HTTP server → API routes: mounts routes
cmd/main.go - HTTP server → pprof endpoint: mounts pprof
cmd/main.go - HTTP client → HTTP server: sends requests
README.md - API routes → User registration: routes registration
internal/handlers/register_handler.go - API routes → Post endpoints: routes posts
internal/handlers/register_handler.go - API routes → Like endpoint: routes post actions
internal/handlers/register_handler.go - User registration → Blog service: registers user
internal/handlers/register_handler.go - Post endpoints → Blog service: creates or lists
internal/handlers/posts_handler.go - Like endpoint → Blog service: validates like
internal/handlers/like_handler.go - Like endpoint → Like queue: submits job
internal/handlers/like_handler.go - Blog service → In-memory state: reads and writes
internal/service/service.go - Blog service → User and post: uses models
internal/service/service.go - Blog service → Post ID counter: allocates IDs
internal/service/service.go - HTTP server → Blog service: initializes
cmd/main.go - HTTP server → Like queue: configures worker
cmd/main.go - Like queue → Like worker: dispatches jobs
internal/queue/like_queue.go - HTTP server → Blog service: worker calls likes
cmd/main.go - Blog service → Event logger: publishes events
internal/service/service.go - HTTP server → Event logger: initializes logger
cmd/main.go - HTTP server → Event logger: logs queue failures
cmd/main.go - Event logger → stdout: writes events
internal/logger/logger.go - HTTP client → pprof endpoint: requests profiles
README.md