Anchor is a framework for building serverless and reliable applications in speed of light with confidence.
Anchor provides the following features:
- Authentication & Authorization with Macaroons
- Asynchronous task management with at-least-once delivery
- Database query interface with sqlc
- HTTP API server with Fiber
- Plugin system for easily extending the framework
The core philosophy of Anchor is to provide confidence in the codebase by:
- Use YAML to define schema and generate interfaces to avoid runtime errors of missing implementation, meaning you can catch errors at compile time.
- Use event-driven architecture to build a system that is easy to reason about and easy to extend.
- All modules are mockable and can be tested with ease.
go install github.com/cloudcarver/anchor@latest
anchor init .
- Define the HTTP schema
api/v1.yaml
with YAML format.
openapi: 3.0.0
info:
title: Anchor API
version: 1.0.0
description: Anchor API
paths:
/api/v1/counter:
get:
operationId: getCounter
summary: Get the counter value
responses:
"200":
description: The counter value
- Define the database schema
sql/migrations/0001_init.up.sql
with SQL format.
CREATE TABLE IF NOT EXISTS counter (
value INTEGER NOT NULL DEFAULT 0
);
-- name: GetCounter :one
SELECT value FROM counter LIMIT 1;
-- name: IncrementCounter :exec
UPDATE counter SET value = value + 1;
- Define the task schema
api/tasks.yaml
with YAML format.
tasks:
incrementCounter:
description: Increment the counter value
cron: "*/1 * * * *" # every 1 seconds
- Run code generation.
anchor generate
- Implement the interfaces.
func (h *Handler) GetCounter(c *fiber.Ctx) error {
return c.JSON(apigen.Counter{Count: 0})
}
func (e *Executor) IncrementCounter(ctx context.Context, params *IncrementCounterParameters) error {
return e.model.IncrementCounter(ctx)
}
-
Configure the application using environment variables.
-
Build and run the application.