Skip to content

Instantly share code, notes, and snippets.

@suntong
Created May 5, 2019 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suntong/bae094f0911a7d6d2d571283c8c9f648 to your computer and use it in GitHub Desktop.
Save suntong/bae094f0911a7d6d2d571283c8c9f648 to your computer and use it in GitHub Desktop.
# golang:latest as build-env
FROM golang:latest AS build-env
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN cd /app && GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp .
# go build -o myapp
FROM alpine
RUN mkdir /app
COPY --from=build-env /app/myapp /app
EXPOSE 8080
ENTRYPOINT ["/app/myapp"]
package main
import (
"net/http"
"strings"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
message := r.URL.Path
message = strings.TrimPrefix(message, "/")
message = "Hello " + message
w.Write([]byte(message))
}
func main() {
http.HandleFunc("/", sayHello)
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment