Socket
Socket
Sign inDemoInstall

github.com/bbengfort/catena

Package Overview
Dependencies
7
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/bbengfort/catena

Package catena implements a simple social graph API.


Version published

Readme

Source

Catena

The links that associate us.

GoDoc Go Report Card Build Status codecov

Database Migrations

The schema of the database is managed through migration files that can be applied or rolled back to ensure the database version matches the expected version of the server.

NOTE: Currently only PostgreSQL is tested with this method.

To create a migration, create a new SQL file in the migrations folder with the format XXXX_my_migration.sql where the XXXX should be the next migration number in sequence and the text describes the migration. You can use the catena command to do this as long as you're in the project root:

$ go run ./cmd/catena --new my revision name

In the SQL file you should have the following two comments:

-- migrate: up
-- insert up migration sql here

-- migrate: down
-- insert down migration sql here

All of the SQL under -- migrate: up will be run when the migration is applied and all of the SQL under -- migrate: down will be run if the migration is rolled back. Ensure that you separate multiple SQL commands with ; because they will be executed all at once and with newlines removed.

Next generate the migration by running go generate in the project root:

$ go generate ./...

This will generate the migrations code from the SQL files and allow you to apply it with the catena migrate command.

Server Mux

The goal of catena is to do as much as possible from scratch in order to demonstrate an extremely lightweight web api server and concepts such as database migration, context handling, logging, tracing, etc. This is primarily for the purposes of my deeper exploration of Go rather than to develop a production-grade API.

When it comes to route multiplexing however, the http.ServeMux is an excellent example of static routing but does not scale well to the dynamic routing required by a REST API. In the past I've attempted to implement a prefix trie for this routing, but in order to focus on other efforts in this code, I've selected httprouter based on its lightweight tree structure and benchmarks. Potentially in the future I will attempt to write my own radix tree structure and benchmark it specifically to this API - but for now it provides the smallest abstraction set and allows me to focus on middleware and the API itself.

FAQs

Last updated on 31 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc