Skip to content

ImparaAI/go-figure-api

Repository files navigation

Go Figure API

A Go backend service for the go figure web app. This is inspired by the Fourier series circle drawings video by 3Blue1Brown.

This application accepts a series of continuous points captured at even time intervals, and a requested number of draw vectors to calculate. The calculation job is put onto a queue that is processed continuously. Once the job is complete, the results are available at the drawing's uri as a list of vectors with real and imaginary parts that can then be animated.

Build Status Go Report Card

Routes

/drawing

Method: POST

Input:

{
	"points": [
		{"x": 143, "y": 45, "time": 0},
		{"x": 144, "y": 49, "time": 0.01}
	]
}

Output:

{"id": 1}

/drawing/:id

Method: GET

Output:

{
	"id": 1,
	"points": [
		{"x": 143, "y": 45, "time": 0},
		{"x": 144, "y": 49, "time": 0.01}
	],
	"drawVectors": {
		"calculated": [
			{"n": 0, "real": 0, "imaginary": 2},
			{"n": 1, "real": 0, "imaginary": 2.5},
			{"n": -1, "real": 0.5, "imaginary": 2.7}
		],
	},
	"dateCreated": "2020-01-01 12:00:00"
}

/drawings/recent

Method: GET

Output:

[
	{
		"id": 2,
		"svgPath": "M 364 113 L 364 113 L 357 113 L 348 113 L 342 113 L 337 113 L 333..."
	},
	{
		"id": 1,
		"svgPath": "M 364 113 L 364 113 L 357 113 L 348 113 L 342 113 L 337 113 L 333..."
	}
]

Tests

Tests require the presence of a mysql database connection. You can easily get this by running this from the project root:

docker-compose up

Wait for the mysql container spin up and then run the tests like:

docker-compose exec api sh -c "go test -v ./.../test"