Skip to content

Commit 4ae1d32

Browse files
committed
init
0 parents  commit 4ae1d32

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

DockerFile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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"]

format.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, %s!

main.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

0 commit comments

Comments
 (0)