File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ # Start from the latest golang base image
2+ FROM golang:latest as builder
3+
4+ # Set the Current Working Directory inside the container
5+ WORKDIR /app
6+
7+ # Copy the source from the current directory to the Working Directory inside the container
8+ COPY . .
9+
10+ # Build the Go app
11+ RUN go build -o main .
12+
13+
14+ ######## Start a new stage from scratch #######
15+ FROM alpine:latest
16+
17+ WORKDIR /root/
18+
19+ # Copy the Pre-built binary file from the previous stage
20+ COPY --from=builder /app/main .
21+
22+ # Expose port 8080 to the outside world
23+ EXPOSE 8080
24+
25+ # Command to run the executable
26+ CMD ["./main"]
Original file line number Diff line number Diff line change 1+ Hello, %s!
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "net/http"
6+ "os"
7+ "io/ioutil"
8+ )
9+
10+ func main () {
11+ port := os .Getenv ("PORT" )
12+ if (port == "" ) {
13+ port = "8080"
14+ }
15+
16+ dat , err := ioutil .ReadFile ("format.txt" )
17+ if (err != nil ) {
18+ panic (err )
19+ }
20+ fmt .Println ("Format: " + string (dat ))
21+
22+ fmt .Println ("Start listen port " + port )
23+
24+ http .HandleFunc ("/" , HelloServer )
25+ http .ListenAndServe (":" + port , nil )
26+ fmt .Println ("Terminating" )
27+ }
28+
29+ func HelloServer (w http.ResponseWriter , r * http.Request ) {
30+ fmt .Fprintf (w , "Hello, %s!" , r .URL .Path [1 :])
31+ }
You can’t perform that action at this time.
0 commit comments