Skip to content

Commit cd4b6ef

Browse files
author
bsnux
committed
simple ping/pong HTTP server
1 parent f582e79 commit cd4b6ef

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

pinghtml/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.14.1 as builder
2+
ENV NAME "pinghtml"
3+
WORKDIR /opt
4+
COPY . .
5+
RUN GOOS=linux CGO_ENABLED=0 go build -o bin/$NAME main.go
6+
7+
FROM alpine:3.11.5
8+
RUN apk --no-cache add ca-certificates
9+
WORKDIR /opt
10+
COPY --from=builder /opt/bin/$NAME .
11+
CMD ["/opt/pinghtml"]

pinghtml/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module pinghtml
2+
3+
go 1.14

pinghtml/main.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Simple web server listening on port 8080
2+
//
3+
// Launch this program, open a new terminal, then type:
4+
// `curl -L http://localhost:8080`
5+
package main
6+
7+
import (
8+
"fmt"
9+
"log"
10+
"net/http"
11+
)
12+
13+
func handler(w http.ResponseWriter, r *http.Request) {
14+
fmt.Fprintf(w, "<html><body>pong</body></html>")
15+
}
16+
17+
func main() {
18+
http.HandleFunc("/", handler)
19+
log.Println("Starting server...")
20+
log.Fatal(http.ListenAndServe(":8080", nil))
21+
}

0 commit comments

Comments
 (0)