xm-rest-api

command module
v0.0.0-...-08ad29a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2021 License: MIT Imports: 5 Imported by: 0

README

XM Rest Api

This is an interview showcase work and not intended for production usage

Overview

XM Golang Exercise - v21.0.0

Config

+----------------------------------+----------+----------------+-------------------------+
|               ENV                |   Type   |    Default     |       Description       |
+----------------------------------+----------+----------------+-------------------------+
| PORT                             | int      | 9090           | Service Port            |
| METRICS_PORT                     | int      | 7000           | Metrics Port            |
| KAFKA_PRODUCER_BOOTSTRAP_SERVERS | []string | localhost:9092 | Kafka Bootstrap Servers |
| DATABASE_URL                     | string   | root:@/test    | Database Connect Url    |
+----------------------------------+----------+----------------+-------------------------+

Quick start

Build the binary

go build -ldflags="-s -w" -o xm-rest-api main.go

Run the Binary

./xm-rest-api

Testing

Start Services on docker-compose, This might take 20-30min for
the first time until you pull all the required dependencies.

docker-compose up -d --build

Start the testing without building xm-rest-api image

 docker-compose up -d

NOTE: if you receive following error, remove the orphan container
ERROR: for api Container "3e997fbed7c1" is unhealthy. ERROR: Encountered errors while bringing up the project.

Stop testing environment

 docker-compose down 

NOTE: If you do not stop testing env properly, you'll get errors on the next start

Create Company

curl --location --request PUT 'http://localhost:9090/company' \
--header 'X-FORWARDED-FOR: 31.153.207.255' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":"ABC2",
    "code":"123123",
    "country":"sri lanka",
    "website":"",
    "phone":123123
}'

Update Company

curl --location --request POST 'http://localhost:9090/company' \
--header 'X-FORWARDED-FOR: 31.153.207.255' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":"ABC2",
    "code":"123123",
    "country":"sri lanka2",
    "website":"234234",
    "phone":123123
}'

Delete Company

curl --location --request DELETE 'http://localhost:9090/company?code=123123' \
--header 'X-FORWARDED-FOR: 31.153.207.255'

Get Company(s)

curl --location --request GET 'http://localhost:9090/company?code=123123&name=ABC2'

Assumptions

  1. Company code is unique for a company
  2. Only one mobile phone is available for a company
  3. Phone number is a number,
  4. Website is a optional field

Improvements

  1. Add support to Multiple Filters on the same type
ex:- 
  GET /company?code=123123&code=454545
  1. Data Field Validation
  2. Multiple Source Data write failure handling
  3. Topic Automatic creation if not exist
  4. Database data indexing

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
repositories
stream

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL