Giter Club home page Giter Club logo

apiingolang's Introduction

apiingolang

API in Go

This Go project consists of 2 component:

  1. API server (serving a GET API that returns 3 unique activities every time it is called as response)
  2. DB worker (this inserts the fetched activities in postgres database)

postgresql queires

- create database test

- create table activity (
    id serial primary key,
    activity_key varchar(16) not null,
    activity_content VARCHAR(512),
    created_at timestamp default current_timestamp
  );
  
- CREATE INDEX idx_activity_key ON activity (activity_key);

api end point

  • /api/public/vi/activities
  • the api serves on port=9000
  • Response code
    - 200 : success
    - 408 : time out (> 2 second)
    - 500 : panic in server

how to run

  • As Docker Container
    • Run the start.sh (./start.sh) script file to start, and stop.sh (./stop.sh) file to stop
  • On local machine
    • Run go run . Postgres DB connection details should be added in config/config.local.json file

worker pool

  • the program contains a generic worker pool implementation in go for parallel processing of request. At the same time the workers can be configured as per requirement. This is better than simply spawning go routines, if we were to spawn multiple go routine for a single request, the system can crash when there is a outburst of request. Also spawning a new go routine is costlier than a worker go routine that processes task by fetching from a job queue (channel)
  • Here we have 2 worker pool:
    • First with 3 worker that is used only for calling [https://www.boredapi.com/api/activity] to fetch activities, this restricts out application to hit at max 3 times at any given point.
    • Second is a general worker pool used to execute task like db insert.

apiingolang's People

Contributors

sahanirahul avatar

Stargazers

 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.