This repository contains an example of Rest API for simple Todo managing written on Go.
The main goal and usage are described here.
- The latest Go language version should be installed.
- We use Go dependency management tool. So, it should be installed also.
- Use
git clone git@github.com:VS-work/go-todo-server.gitto get the repository. - Use
cd go-todo-serveranddep ensureto install all expected dependencies of the project. - This application works with SQLite database
This project contains a minimum of required API tests. You can see these tests here.
Run go test or go test -v if you want to get the detailed information regarding tests passing.
Run go build. You will see go-todo-server binary file in the root directory of the project. Important: The file above does NOT include to the repository and it will be ignored on future commits. More info here.
You just need to run go-todo-server. It has the following parameters:
- Path to SQLite database file which will be used by the application.
- A host that will be used as
Access-Control-Allow-Originheader value (CORS requirement). You can see related point int the following part of code - Notification email
For example, the following command
./go-todo-server ./db/todos_test.db http://localhost:3000 foo@bar.com
will start API server and allow to get requests from http://localhost:3000 and will use ./db/todos_test.db file as the current database.
There are 3 kinds of notifictions: todo creation, todo modification and todo removing.
Important note: this application use port 3001 on local use.
There is only Heroku deployment supporting.
There are following features regarding deployment:
- Please follow instructions to deploy the application on
Heroku - Main settings regarding
Herokuare placed here. This file contains command-runner that includes the database file name and allowed origin (seeRun locallyabove) - There is an empty DB file (SQLite) that used as a database on Heroku's server.
- Because this API server and its frontend counterpart are deployed on different hosts it's very important CORS policy especially
Allowed Origins. It's a very bad idea to use*as allowed origins. That's whyAllowed Originsshould contain only hosts that will really work with this API server. In this case, there is https://vs-work.github.io. - If you want to use the API on Heroku go to the following URL: https://dry-woodland-14649.herokuapp.com/
This application has integration with Sendgrid cloud email service and it sends an email after todo creation, modification, and removing. Please set SENDGRID_API_KEY environment variable on your local PC or Heroku application if you want to activate this feature.
We don't guarantee Todo data persistence because this application is just an example. All your data will be lost after each deployment!