Skip to content

Commit c808907

Browse files
committed
Add docker file and docker compose
1 parent 58aa88c commit c808907

File tree

4 files changed

+56
-13
lines changed

4 files changed

+56
-13
lines changed

17-Http/07-MiniProject/.DockerFile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.18-alpine as builder
2+
3+
WORKDIR /app
4+
5+
COPY go.* ./
6+
RUN go mod download
7+
8+
COPY . ./
9+
10+
RUN go build -v -o server
11+
12+
COPY ./ ./app/server
13+
EXPOSE 80
14+
CMD ["/app/server"]

17-Http/07-MiniProject/handlers/movie.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ func GetMovies(w http.ResponseWriter, req *http.Request) {
4545
}
4646

4747
// parse the movie data into json format
48-
moviesJSON, err := json.Marshal(&movies)
49-
if err != nil {
50-
utils.SetResult(w, http.StatusInternalServerError, nil, utils.ApiError{Id: "jsonMarshal", Message: "Error parsing the movie data" + err.Error()})
51-
return
52-
}
48+
// moviesJSON, err := json.Marshal(&movies)
49+
// if err != nil {
50+
// utils.SetResult(w, http.StatusInternalServerError, nil, utils.ApiError{Id: "jsonMarshal", Message: "Error parsing the movie data" + err.Error()})
51+
// return
52+
// }
5353

54-
utils.SetResult(w, http.StatusOK, moviesJSON, nil)
54+
utils.SetResult(w, http.StatusOK, movies, nil)
5555
}
5656

5757
func GetMovie(w http.ResponseWriter, req *http.Request) {
@@ -75,13 +75,13 @@ func GetMovie(w http.ResponseWriter, req *http.Request) {
7575
}
7676

7777
// parse the movie data into json format
78-
movieJSON, err := json.Marshal(&movie)
79-
if err != nil {
80-
utils.SetResult(w, http.StatusInternalServerError, nil, utils.ApiError{Id: "jsonMarshal", Message: "Error parsing the movie data" + err.Error()})
81-
return
82-
}
78+
// movieJSON, err := json.Marshal(&movie)
79+
// if err != nil {
80+
// utils.SetResult(w, http.StatusInternalServerError, nil, utils.ApiError{Id: "jsonMarshal", Message: "Error parsing the movie data" + err.Error()})
81+
// return
82+
// }
8383

84-
utils.SetResult(w, http.StatusOK, movieJSON, nil)
84+
utils.SetResult(w, http.StatusOK, movie, nil)
8585
}
8686

8787
func AddMovie(w http.ResponseWriter, req *http.Request) {

17-Http/07-MiniProject/management/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func Run() {
1010
mux := http.NewServeMux()
11-
mux.Handle("/users/", &handlers.MovieHandler{})
11+
mux.Handle("/movies/", &handlers.MovieHandler{})
1212
server := &http.Server{
1313
Addr: ":8080",
1414
ReadTimeout: time.Second * 10,

20-Docker/docker-compose.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: '3'
2+
services:
3+
postgres:
4+
container_name: pgdb
5+
image: postgres
6+
hostname: postgres
7+
ports:
8+
- "5432:5432"
9+
environment:
10+
POSTGRES_USER: postgres
11+
POSTGRES_PASSWORD: admin
12+
POSTGRES_DB: TEST_SM
13+
volumes:
14+
- postgres-data:/var/lib/postgresql/data
15+
restart: unless-stopped
16+
17+
pgadmin:
18+
image: dpage/pgadmin4
19+
depends_on:
20+
- postgres
21+
ports:
22+
- "8090:80"
23+
environment:
24+
PGADMIN_DEFAULT_EMAIL: hamed@test.com
25+
PGADMIN_DEFAULT_PASSWORD: admin
26+
restart: unless-stopped
27+
28+
volumes:
29+
postgres-data:

0 commit comments

Comments
 (0)