Skip to content

RESTful API written in Go. uses Postgres Database and Julien Schmidt router, NO ORMs just plain database/sql methods

Notifications You must be signed in to change notification settings

RonaldCrb/go-pg-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GO and PostgreSQL JSON REST API

this is a sample RESTful API written in go.

launching a containerized database for testing purposes

First you need to Install Docker

then run this command to run a postgres container which maps port 5432 to localhost:5432

docker run --name pg -p 5432:5432 -d postgres

then this command will give you a psql shell with the appropriate user:

docker exec -it pg psql postgres postgres

users Package

after database is created, run this command to create a users table

CREATE TABLE users (
	id       	  SERIAL PRIMARY KEY NOT NULL,
	firstName     	  VARCHAR(255) NOT NULL,
	LastName 	  VARCHAR(255) NOT NULL,
	email		  VARCHAR(255) NOT NULL,
        createdAt         TIMESTAMP NOT NULL DEFAULT NOW(),
        updatedAt         TIMESTAMP NOT NULL DEFAULT NOW()
);

endpoints

You can execute the binary file directly by typing

./main

this will make available the following endpoints:

returns a JSON object with: a greeting message

returns a JSON object with: a healthcheck status message and timestamp

returns a JSON object with: a confirmation message and status code

returns a JSON array with: user objects

returns a JSON object with: user properties

returns a JSON object with: a confirmation message and status code

returns a JSON object with: a confirmation message and status code

lbtc package

first create this table

CREATE TABLE btcoffers (
  ID SERIAL PRIMARY KEY NOT NULL,
  Title VARCHAR(255) NOT NULL,
	Trader VARCHAR(255) NOT NULL,
	Bank VARCHAR(255) NOT NULL,
	Currency VARCHAR(255) NOT NULL,
	Reputation SMALLINT,
	Price FLOAT,
	Min FLOAT,
	Max FLOAT,
	Index SMALLINT NOT NULL,
  CreatedAt         TIMESTAMP NOT NULL DEFAULT NOW(),
  UpdatedAt         TIMESTAMP NOT NULL DEFAULT NOW()
);

About

RESTful API written in Go. uses Postgres Database and Julien Schmidt router, NO ORMs just plain database/sql methods

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages