From f237816e871fd60afbd91a7eab23a229d484bc41 Mon Sep 17 00:00:00 2001 From: AnirbanB13 Date: Sat, 30 Aug 2025 17:30:14 +0000 Subject: [PATCH 1/2] Successfully Dockerized go-web-app --- Dockerfile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..ea8a2e736 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:1.25 as build + +WORKDIR /app + +COPY go.mod ./ + +RUN go mod download + +COPY . . + +RUN go build -o main . + +FROM gcr.io/distroless/base + +COPY --from=build /app/main . + +COPY --from=build /app/static ./static + +EXPOSE 8081 + +CMD ["/main"] From 825a439f4539bba727ecfc9cbaa88d4947a8dfe3 Mon Sep 17 00:00:00 2001 From: AnirbanB13 Date: Sat, 30 Aug 2025 17:32:58 +0000 Subject: [PATCH 2/2] Replaced the root / handler with homePage --- main.go | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index b04eee299..5e9c9bc5f 100644 --- a/main.go +++ b/main.go @@ -1,39 +1,44 @@ package main import ( - "log" - "net/http" + "fmt" + "log" + "net/http" ) func homePage(w http.ResponseWriter, r *http.Request) { - // Render the home html page from static folder - http.ServeFile(w, r, "static/home.html") + // Render the home html page from static folder + http.ServeFile(w, r, "static/home.html") } func coursePage(w http.ResponseWriter, r *http.Request) { - // Render the course html page - http.ServeFile(w, r, "static/courses.html") + // Render the course html page + http.ServeFile(w, r, "static/courses.html") } func aboutPage(w http.ResponseWriter, r *http.Request) { - // Render the about html page - http.ServeFile(w, r, "static/about.html") + // Render the about html page + http.ServeFile(w, r, "static/about.html") } func contactPage(w http.ResponseWriter, r *http.Request) { - // Render the contact html page - http.ServeFile(w, r, "static/contact.html") + // Render the contact html page + http.ServeFile(w, r, "static/contact.html") } func main() { - - http.HandleFunc("/home", homePage) - http.HandleFunc("/courses", coursePage) - http.HandleFunc("/about", aboutPage) - http.HandleFunc("/contact", contactPage) - - err := http.ListenAndServe("0.0.0.0:8080", nil) - if err != nil { - log.Fatal(err) - } + // Root (/) should serve the homepage instead of just a text message + http.HandleFunc("/", homePage) + + http.HandleFunc("/home", homePage) + http.HandleFunc("/courses", coursePage) + http.HandleFunc("/about", aboutPage) + http.HandleFunc("/contact", contactPage) + + fmt.Println("🚀 Server running on port 8081...") + err := http.ListenAndServe(":8081", nil) + if err != nil { + log.Fatal(err) + } } +