Skip to content

DiogoSantoss/persistent-web-server-go

Repository files navigation

Persistent Web Server

Small web server written in golang with persistent data in postgresql database.

Table of content

Install

You can install Go from Go official website or by doing

wget https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
tar -xvf go1.18.1.linux-amd64.tar.gz
mv go go-1.18.1
sudo mv go-1.18.1 /usr/local

You can install Postgresql from PostgreSQL official website or by doing

sudo apt install postgresql 

Configuration File

Rename example.env to .env and fill its fields
Should look something like this

DIALECT="postgres"
DB_HOST="localhost"
DB_PORT="5432"
DB_USER="user"
DB_NAME="car_data"
DB_PASSWORD="password"

Run

To start postgresql and create database

sudo service postgresql start
createdb car_data

Run web server

go run main.go

Run with Docker

Create a network

docker network create go-postgres-network

Run the postgres container

docker run -d \
-p 5432:5432 \
-e POSTGRES_PASSWORD=password \
--name postgresdb \
--net go-postgres-network \
postgres

Create the database inside the container

docker ps
docker exec -it 8c67db24bfcf bash
psql -U postgres
CREATE DATABASE car_data;

Build the go image

docker build . \
-t go-postgres-server

Run the container

docker run -it \
-p 8080:5000 \
--network go-postgres-network \
go-web-server

Run with Docker Compose

Run the docker compose

docker-compose -f docker-compose.yaml up

To turn off

docker-compose -f docker-compose.yaml down

Additional Docker commands

List running containers

docker ps

List stored images

docker images

List networks

docker network ls

Push Docker image to Gitlab

docker login registry.gitlab.com
docker build -t registry.gitlab.com/psem/recruitment-software/diogosantoss/persistent-web-server .
docker push registry.gitlab.com/psem/recruitment-software/diogosantoss/persistent-web-server

API Testing

Use request.py to stress test the API

Build with

About

Persistent web server built in Go with PostgreSQL database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published