This is a simple example of writing an API in Go. I'm using this project to practice my knowledge of Go.
- Go version 1.22 or higher
- nodemon package from npm (for development server)
- Redis server. Upstash is free 😉
REDIS_URL
: (required) The URL of the redis instance to connect to.PORT
: The http port the server will listen on. Defaults tolocalhost:8090
.
To get started with this repo, follow these steps:
- Clone the repository:
git clone https://github.com/valtlfelipe/go-api.git
- Install dependencies:
cd go-api
go mod tidy
- Run locally:
make run
The API should now be running at http://localhost:8090
.
- Run tests:
make test
- Test coverage:
make test-coverage
# open coverage/coverage.html
Test coverage files will be available inside coverage/
folder.
- URL:
/tasks
- Method:
POST
- Headers:
- Content-Type: application/json
{
"name": "Task Title"
}
- URL:
/tasks/{id}
- Method:
GET
{
"id": "578f2d5e-c4cc-4ea8-b98d-47690e8bb6a5",
"name": "Task Title"
}