From 6b7faf1899e37a8ceedc427ad1666630a4312567 Mon Sep 17 00:00:00 2001 From: Shah Ismail Date: Thu, 10 Sep 2020 15:27:23 +0300 Subject: [PATCH] Basic cleaning --- Makefile | 10 ++++++++++ main.go => cmd/genityapp/main.go | 15 +++++---------- db.env | 3 +++ db_dump | 4 ---- ddl_01.sql | 1 + dml_01.sql | 1 + docker-compose.yml | 22 +++++++++++++--------- api.go => genityapp/api.go | 0 web.env | 6 ++++++ 9 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 Makefile rename main.go => cmd/genityapp/main.go (78%) create mode 100644 db.env delete mode 100644 db_dump create mode 100644 ddl_01.sql create mode 100644 dml_01.sql rename api.go => genityapp/api.go (100%) create mode 100644 web.env diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0e523d5 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +export NAME=genityapp + +build: + docker-compose build + +run: build + docker-compose up + +build-binary: + GOOS=linux GOARCH=amd64 go build \ No newline at end of file diff --git a/main.go b/cmd/genityapp/main.go similarity index 78% rename from main.go rename to cmd/genityapp/main.go index af6072a..10f60ef 100644 --- a/main.go +++ b/cmd/genityapp/main.go @@ -22,11 +22,11 @@ func main() { initDb() defer db.Close() - http.HandleFunc("/api/users", UserGetHandler) - http.HandleFunc("/api/user", UserPostHandler) + http.HandleFunc("/get-data", UserGetHandler) + http.HandleFunc("/post-data", UserPostHandler) - fmt.Println("Listening on :8080") - log.Fatal(http.ListenAndServe(":8080", nil)) + fmt.Println("Listening on :5000") + log.Fatal(http.ListenAndServe(":5000", nil)) } @@ -48,16 +48,11 @@ func initDb() { panic(err) } fmt.Println("Successfully connected!") - - - - - } func dbConfig() map[string]string { conf := make(map[string]string) - conf[dbhost] = "poc-golang-postgres-docker_db_1" + conf[dbhost] = "genitywebapp_db_1" conf[dbport] = "5432" conf[dbuser] = "root_user" conf[dbpass] = "shahzad12" diff --git a/db.env b/db.env new file mode 100644 index 0000000..b81c7e3 --- /dev/null +++ b/db.env @@ -0,0 +1,3 @@ +POSTGRES_DB=db_genity +POSTGRES_USER=root_user +POSTGRES_PASSWORD=shahzad12 \ No newline at end of file diff --git a/db_dump b/db_dump deleted file mode 100644 index cfacdf5..0000000 --- a/db_dump +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE users ( user_id serial PRIMARY KEY, title VARCHAR ( 50 ) UNIQUE NOT NULL, created_on TIMESTAMP NOT NULL); -INSERT INTO users (title,created_on) VALUES('shahzad','2013-06-01'); - - diff --git a/ddl_01.sql b/ddl_01.sql new file mode 100644 index 0000000..e9b8a1d --- /dev/null +++ b/ddl_01.sql @@ -0,0 +1 @@ +CREATE TABLE users (user_id serial PRIMARY KEY, title VARCHAR ( 50 ) UNIQUE NOT NULL, created_on TIMESTAMP NOT NULL); \ No newline at end of file diff --git a/dml_01.sql b/dml_01.sql new file mode 100644 index 0000000..0ee150a --- /dev/null +++ b/dml_01.sql @@ -0,0 +1 @@ +INSERT INTO users (title,created_on) VALUES('shahzad','2013-06-01'); \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 22eb0de..5d74d84 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,21 +2,25 @@ version: '3' services: db: image: postgres - environment: - POSTGRES_DB: db_genity - POSTGRES_USER: root_user - POSTGRES_PASSWORD: shahzad12 + env_file: + - ./db.env volumes: - - db_postgres:/var/lib/postgresql/data - ports: - - "5436:5432" + - ./db_postgres:/var/lib/postgresql/data + - ./ddl_01.sql:/docker-entrypoint-initdb.d/10_schema.sql + - ./dml_01.sql:/docker-entrypoint-initdb.d/20_insert.sql + expose: + - "5432" + restart: always networks: - genity_network - app: + web: build: "" command: [ "go", "run", "main.go","api.go"] + env_file: + - ./web.env ports: - - "8080:8080" + - "5000:5000" + restart: always depends_on: - db links: diff --git a/api.go b/genityapp/api.go similarity index 100% rename from api.go rename to genityapp/api.go diff --git a/web.env b/web.env new file mode 100644 index 0000000..ada0a56 --- /dev/null +++ b/web.env @@ -0,0 +1,6 @@ +COMPOSE_PROJECT_NAME=genitywebapp +dbhost=genityapp_db_1" +dbport=5432 +dbuser=root_user +dbpass=shahzad12 +dbname=db_genity \ No newline at end of file