This repository contains the golang api server written on top of fiber framework
- go version >= 1.20 https://golang.org/
- if you're on a sensible o/s:
$ pacman -S go go-tools
- if you're on Mac, you can install using Brew
brew install go
- You can install brew using
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- You can install brew using
- for Windows/installers please visit Golang Downloads
- if you're on a sensible o/s:
- >= python 3.6
pip install --user pypyr
Whilst we are not too prescriptive about the location of git repositories on your development machine, Golang does expect a certain structure so that it can store packages, binaries and find source code. A sample root directory structure for all git repositories may look something like this:
/home/{user}/projects
Then set GOPATH environment variable to point to this location:
GOPATH="$HOME/projects"
export GOPATH
To make this more permanent, add the above lines into your .bash_profile file in your home directory. Then, within this directory, create the following sub-directories:
/home/{user}/projects/bin
/home/{user}/projects/pkg
/home/{user}/projects/src
By default when the go tools are installed it creates $HOME/go which can be used, however, if you have many projects that support different languages then a go directory might be unintuitive as a project root directory.
Golang projects need to be located within the src directory of the GOPATH location. Given this restriction, it makes sense to follow general convention when it comes to defining the directories for git repository locations, organisations and projects within the src directory, as follows:
$GOPATH/src/{repo-location}/{organisation}/{project}
In this case of this repository, this equates to:
$GOPATH/src/github.com/rahul2393/city-falcon-assignment/
All the server configuration can be managed via a environment values.
export LISTEN_ADDRESS_HTTP=8080
export DB_URL=postgres//{user}:{password}@{host}:5432/city_falcon?sslmode=disable
export LOG_QUERY=true
go build -v -o bin/server . #creates a binary to run server
Fetches the slow queries running on Postgres instance, API supports filtering on pg_stats_activity table coloumns
Example:
curl --location 'http://localhost:8080/slow-queries?filter=database_name!%3D%22%22'
Creates an entry in the database
Example:
curl --location 'http://localhost:8080/entry' \
--header 'Content-Type: application/json' \
--data '{
"version": 2
}'
List all the entries in the database
Example:
curl --location 'http://localhost:8080/entry/39a4fe61-4472-4205-99e0-96aa5258b1ab'
Note: To fetch deleted entries pass query param showDeleted=true
List all the entries in the database
Example:
curl --location 'http://localhost:8080/entries'
Updates the entry identified by unique ID in the database
Example:
curl --location --request PUT 'http://localhost:8080/entry/39a4fe61-4472-4205-99e0-96aa5258b1ab?updateMask=version' \
--header 'Content-Type: application/json' \
--data '{
"version": 3
}'
Soft deletes an entry from the database
Example:
curl --location --request DELETE 'http://localhost:8080/entry/39a4fe61-4472-4205-99e0-96aa5258b1ab'
- LIST APIs pagination using
pageSize
andpageOffset
query parameters. - GET SLOW Query supports filtering by SELECT, INSERT,UPDATE, DELETE using filter parameter example query to fetch slow queries beginning with insert statements
curl --location 'http://localhost:8080/slow-queries?filter=query%3A%22INSERT%22'
- In memory cache is used with TTL of 30 seconds and key API path.
HTTP > handler/usecase
handler/usecase > repository (Postgres)
handler/usecase < repository (Postgres)
HTTP < usecase