Code Monkey home page Code Monkey logo

city-falcon-assignment's Introduction

City Falcon Entity Microservice

Overview

This repository contains the golang api server written on top of fiber framework

Prerequisites

Software

  • 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)"
    • for Windows/installers please visit Golang Downloads
  • >= python 3.6
    • pip install --user pypyr

Project root directory structure

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.

Project directories within root directory structure

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/

Server configuration

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

Day-to-day build

go build -v -o bin/server . #creates a binary to run server

APIs

GET Slow Queries

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'

POST Entry

Creates an entry in the database

Example:

curl --location 'http://localhost:8080/entry' \
--header 'Content-Type: application/json' \
--data '{
    "version": 2
}'

GET EntryBYID

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

GET Entries

List all the entries in the database

Example:

curl --location 'http://localhost:8080/entries'

PUT Entry

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
}'

Delete Entry

Soft deletes an entry from the database

Example:

curl --location --request DELETE 'http://localhost:8080/entry/39a4fe61-4472-4205-99e0-96aa5258b1ab'

Server supports

  1. LIST APIs pagination using pageSize and pageOffset query parameters.
  2. 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'
  1. In memory cache is used with TTL of 30 seconds and key API path.

Architecture

HTTP > handler/usecase
       handler/usecase > repository (Postgres)
       handler/usecase < repository (Postgres)
HTTP < usecase

city-falcon-assignment's People

Contributors

rahul2393 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.