Created
May 5, 2019 02:26
-
-
Save suntong/bae094f0911a7d6d2d571283c8c9f648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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