Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
45 changes: 25 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}