Skip to content

Anchor is a framework for building serverless and reliable applications in speed of light with confidence

Notifications You must be signed in to change notification settings

cloudcarver/anchor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anchor

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.

Quick Start

go install github.com/cloudcarver/anchor@latest
anchor init .
  1. 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
  1. 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;
  1. Define the task schema api/tasks.yaml with YAML format.
tasks:
  incrementCounter:
    description: Increment the counter value
    cron: "*/1 * * * *" # every 1 seconds
  1. Run code generation.
anchor generate
  1. 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)
}
  1. Configure the application using environment variables.

  2. Build and run the application.

About

Anchor is a framework for building serverless and reliable applications in speed of light with confidence

Resources

Stars

Watchers

Forks

Packages

No packages published