topic/cleaning #4
10
Makefile
Normal file
10
Makefile
Normal 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
|
|
@ -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
3
db.env
Normal file
|
@ -0,0 +1,3 @@
|
|||
POSTGRES_DB=db_genity
|
||||
POSTGRES_USER=root_user
|
||||
POSTGRES_PASSWORD=shahzad12
|
4
db_dump
4
db_dump
|
@ -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
1
ddl_01.sql
Normal 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
1
dml_01.sql
Normal file
|
@ -0,0 +1 @@
|
|||
INSERT INTO users (title,created_on) VALUES('shahzad','2013-06-01');
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue