Basic cleaning

This commit is contained in:
Şhah İSMAİL 2020-09-10 15:27:23 +03:00
parent d3f66febaf
commit 6b7faf1899
Signed by: shah
GPG key ID: B2B1222785F81AA8
9 changed files with 39 additions and 23 deletions

10
Makefile Normal file
View file

@ -0,0 +1,10 @@
export NAME=genityapp
build:
docker-compose build
run: build
docker-compose up
build-binary:
GOOS=linux GOARCH=amd64 go build

View file

@ -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"

3
db.env Normal file
View file

@ -0,0 +1,3 @@
POSTGRES_DB=db_genity
POSTGRES_USER=root_user
POSTGRES_PASSWORD=shahzad12

View file

@ -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');

1
ddl_01.sql Normal file
View file

@ -0,0 +1 @@
CREATE TABLE users (user_id serial PRIMARY KEY, title VARCHAR ( 50 ) UNIQUE NOT NULL, created_on TIMESTAMP NOT NULL);

1
dml_01.sql Normal file
View file

@ -0,0 +1 @@
INSERT INTO users (title,created_on) VALUES('shahzad','2013-06-01');

View file

@ -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:

6
web.env Normal file
View file

@ -0,0 +1,6 @@
COMPOSE_PROJECT_NAME=genitywebapp
dbhost=genityapp_db_1"
dbport=5432
dbuser=root_user
dbpass=shahzad12
dbname=db_genity