Go-api-cli - Small CLI to fetch data from an API sync and async

Async API Cli

CLI to fetch data on "todos" from a given API in a number of ways. Utilising some basic concurrency via worker pools to speed up multiple API calls.

Tool is centred around 3 core commands with additional arguments.

Architecture

A simplistic take on Clean without infra layer (this was an evening's efforts...). This enables additional adapters such as adding a HTTP layer - just add route handlers and the the app will return the same data without needing to modify the service or domain logic.

Docker Setup

Build

docker build . -t todo-cli

Run

docker run todo-cli -param=value

Commands

fetchall

Fetches entire list of results. Supports result limiting via -count argument.

docker run todo-cli -command=fetchall -count=10

fetchone

Fetches one result - requires -id argument.

docker run todo-cli -command=fetchone -id=20

fetchlist

Accepts an absolute file path (via -list argument). Uses worker pools to fetch results concurrently. data/sample.csv is the sample data.

Can be optimised a little further but is initially taking 2s to make 100 separate calls synchronously compared to ~500ms when fetched async using worker pools.

docker run todo-cli -command=fetchlist -list=/build/data/sample.csv

Result format

Simple logging output. Example:

INFO[0000] Response received    completed=true id=22 title="distinctio vitae autem nihil ut molestias quo" userId=2
INFO[0000] Response received    completed=false id=53 title="qui labore est occaecati recusandae aliquid quam" userId=3
INFO[0000] Response received    completed=false id=31 title="repudiandae totam in est sint facere fuga" userId=2
INFO[0000] Response received    completed=false id=68 title="aut id perspiciatis voluptatem iusto" userId=4

Error format

ERRO[0000] No results found for id: 2323    command=fetchone

Structure

/
│
└───cmd/cli/
│      main.go                          *main entry point*
│   
└───internal/
│   │   
│   └───domain/                         *domain structs*
│   │   │
│   │   └───model/
│   │   │       todo.go                 
│   │   │        
│   │   └───repository/
│   │           todo_repository.go      *repository structs w/ infra*
│   │          
│   └───handlers/cli/                   *handlers for entry point adapters*
│   │       cli.go                      
│   │     
│   └───services/                       *services distributing domain logic*
│           reader.go                   *reader - really this isn't a service and should be relocated*
│           todo.go                     *main todo service*
│   │         
│   └───utils/                       
│           request.go                  *simple HTTP request manager - no auth etc*
│   
│   Dockerfile
│   go.mod
│   go.sum
│   README.md
Similar Resources

A small CLI tool to check connection from a local machine to a remote target in various protocols.

CHK chk is a small CLI tool to check connection from a local machine to a remote target in various protocols.

Oct 10, 2022

BDIX Tester is a small CLI application for testing connectivity BDIX connected servers

BDIX Tester is a small CLI application for testing connectivity BDIX connected servers. It's primary purpose is to check whether a BDIX connected server is accessible from your current ISP or not.

May 17, 2021

Small CLI Tool to store test artifacts in a tamperproof way

Small CLI Tool to store test artifacts in a tamperproof way

Oct 3, 2022

Small CLI based programs for solving structural engineering design problems based on the book 'Structural Concrete'

Small CLI based programs for solving structural engineering design problems based on the book 'Structural Concrete' written by M. Nadim Hassoun and Akhtem Al-Manaseer (edition-6)

Nov 26, 2021

Branch is a small CLI tool to automatically create git branches based on tickets

________ ________ ________ ________ ________ ___ ___ |\ __ \ |\ __ \ |\ __ \ |\ ___ \ |\ ___

Nov 15, 2022

Rpfaudio - A small opinionated cli to create Readium Audiobooks from a directory containing mp3 files

rpfaudio A small opinionated cli to create Readium Audiobooks from a directory c

Feb 18, 2022

Run your MapReduce workloads as a single binary on a single machine with multiple CPUs and high memory. Pricing of a lot of small machines vs heavy machines is the same on most cloud providers.

gomap Run your MapReduce workloads as a single binary on a single machine with multiple CPUs and high memory. Pricing of a lot of small machines vs he

Sep 16, 2022

Small, fast library to create ANSI colored strings and codes. [go, golang]

ansi Package ansi is a small, fast library to create ANSI colored strings and codes. Install Get it go get -u github.com/mgutz/ansi Example import "gi

Dec 23, 2022

A small utility command line application that can recursively download Notion pages

notionbackup A small utility command line application that can recursively download Notion pages. I needed something scriptable that could periodicall

Dec 5, 2022
Yaf - Yet another system fetch that is minimal and customizable
Yaf - Yet another system fetch that is minimal and customizable

Yaf - Yet Another Fetch [Support] [Installation] [Usage] Brief Yet Another Fetch

Oct 11, 2022
Github user stats fetch written in golang
Github user stats fetch written in golang

TACOMA It's like neofetch, but for github users. I saw something similar on reddit and decided to recreate it using only golang. Original inspiration:

Dec 24, 2021
🏗️ Fetch a specific commit without any history (shallow depth w/o cloning)

shallow-fetch-sha ??️ For a given git repository and commit, fetch and checkout just that commit without any history. This can be extremely useful in

Nov 27, 2021
Pi-fetch - get a summary of your pi-hole stats from your terminal

pi-fetch get a summary of your pi-hole stats from your terminal _ ___ _ _ ___|_|___| _|___| |_ ___| |_ | . | |___| _| -_| _

Jan 9, 2022
Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers.
Rclone (

Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers.

Jan 5, 2023
Rclone ("rsync for cloud storage") is a command-line program to sync files and directories to and from different cloud storage providers.
Rclone (

Website | Documentation | Download | Contributing | Changelog | Installation | Forum Rclone Rclone ("rsync for cloud storage") is a command-line progr

Nov 5, 2021
Better sync package for Go.

synx Better sync package for Go. Rationale TODO. Note For better sync/atomic package see atomix. Features Simple API. Easy to integrate. Optimized for

Dec 16, 2022
K8s local storage sync for stateful set's using microk8s-hostpath storage classe

Local Storage Sync for microk8s-hostpath The goal is to be able to sync stateful sets between the different nodes of a cluster to allow the data to be

Nov 1, 2022
Sync local file/directory to pod volume

Sync local file/directory to pod volume

Mar 19, 2022
A small CLI tool to compress and decompress files using Golang
A small CLI tool to compress and decompress files using Golang

Goflate A simple & small CLI tool to compress and decompress files using Golang Usage Install the binary to your local machine with the below command

May 27, 2022