Basic repository with HTTP ping api and db setup

Simple API

Simple REST API with database (postgres) integration

HighLevel Agenda

  • Integrating with postgres (few concepts)
  • Live code walkthrough

Detailed

Check screencast video for more explanation which covers

  • Context on base http ping code
  • DB config
  • DB connections / connection pool
  • Migrations
    • creating basic one
    • running it along with deployment
  • Query
    • Transaction
    • Using context

Gotchas

  • connpool != threads
    • 5-30 would suffice for 10k/s transactions responding in few ms
  • ssl/md5 auth for connecting with DB
  • never overwrite/edit older migration
  • rollback should be tested
  • migrate installation
  • ensure env var sourcing is local to command
  • Use transaction when you've more than one modification

Dependencies

Running

  • create env file .env with following config and modify as necessary
export HOST="localhost"
export PORT=8080

export DB_HOST="localhost"
export DB_USER="postgres"
export DB_PASSWORD="
   
    "
export DB_NAME="simple_api"
export DB_SSL_MODE="disable"
export DB_PORT="5432"

   
  • Ensure you've postgres up and running and run the following to setup the DB
make db.create db.migrate
  • Run the service by running the following command
source local.env && make run

Disclaimer

This code was drafted quickly for a meetup session, and this is not production ready. You could use this as a base but still need to improvise.

Owner
Dinesh Kumar
Go enthusiast, polyglot programmer who love to build awesome things, to enrich people lives.
Dinesh Kumar
Similar Resources

go http api to handle phishing resources requests

go http api to handle phishing resources requests (auth check, prometheus metrics, pushing to rabbit, logging to elasticsearch)

Oct 8, 2021

Fibonacci RESTful API - HTTP server that listens on a given port

Fibonacci RESTful API - HTTP server that listens on a given port

Jan 19, 2022

This is a simple single-host reverse proxy that intercept and save HTTP requests and responses

This is a simple single-host reverse proxy that intercept and save HTTP requests and responses

HTTP Telescope Debug HTTP requests using a reverse proxy. Description This is a simple single-host reverse proxy that intercept and save HTTP requests

Mar 20, 2022

Goget will send a http request, and show the request time, status, response, and save response to a file

Goget will send a http request, and show the request time, status, response, and save response to a file

Feb 9, 2022

Weather api - A Simple Weather API Example With Golang

Example import: import "github.com/mr-joshcrane/weather_api" Example of Library

Jan 5, 2022

Prototype to show how to transform an existing (SOAP) API into a modern streaming API

vSphere Event Streaming Prototype to show how to transform an existing (SOAP) API into a modern HTTP/REST streaming API. Details The vSphere Event Str

Nov 14, 2022

Go (golang) http calls with retries and backoff

pester pester wraps Go's standard lib http client to provide several options to increase resiliency in your request. If you experience poor network co

Dec 28, 2022

Simple HTTP and REST client library for Go

Resty Simple HTTP and REST client library for Go (inspired by Ruby rest-client) Features section describes in detail about Resty capabilities Resty Co

Jan 1, 2023

HTTP Load Testing And Benchmarking Tool

GBench HTTP Load Testing And Benchmarking Tool inspired by Apache Benchmark and Siege. Requirements You need Golang installed and ready on your system

Jan 2, 2020
Http client call for golang http api calls

httpclient-call-go This library is used to make http calls to different API services Install Package go get

Oct 7, 2022
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

fasthttp Fast HTTP implementation for Go. Currently fasthttp is successfully used by VertaMedia in a production serving up to 200K rps from more than

Jan 2, 2023
Speak HTTP like a local. (the simple, intuitive HTTP console, golang version)

http-gonsole This is the Go port of the http-console. Speak HTTP like a local Talking to an HTTP server with curl can be fun, but most of the time it'

Jul 14, 2021
fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client.

fhttp The f stands for flex. fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client. T

Jan 1, 2023
NATS HTTP Round Tripper - This is a Golang http.RoundTripper that uses NATS as a transport.

This is a Golang http.RoundTripper that uses NATS as a transport. Included is a http.RoundTripper for clients, a server that uses normal HTTP Handlers and any existing http handler mux and a Caddy Server transport.

Dec 6, 2022
Simple HTTP package that wraps net/http

Simple HTTP package that wraps net/http

Jan 17, 2022
Http-conection - A simple example of how to establish a HTTP connection using Golang

A simple example of how to establish a HTTP connection using Golang

Feb 1, 2022
A Go HTTP client library for creating and sending API requests
A Go HTTP client library for creating and sending API requests

Sling Sling is a Go HTTP client library for creating and sending API requests. Slings store HTTP Request properties to simplify sending requests and d

Jan 7, 2023
Gotcha is an high level HTTP client with a got-like API
Gotcha is an high level HTTP client with a got-like API

Gotcha is an alternative to Go's http client, with an API inspired by got. It can interface with other HTTP packages through an adapter.

Dec 7, 2022