Created
February 22, 2021 09:02
-
-
Save Formergg/d6ba43f0a943475e302abb32d04821f4 to your computer and use it in GitHub Desktop.
Case 2:使用镜像,部署失败 - 逻辑问题查日志定位
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
# Use the official golang image to create a build artifact | |
FROM golang:1.13 as builder | |
# Create app directory | |
RUN mkdir /app | |
# Add file to /app/ | |
ADD . /app/ | |
# Build the binary | |
WORKDIR /app | |
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . | |
# Run service on container startup | |
FROM alpine:latest | |
WORKDIR /app | |
COPY --from=builder /app/main . | |
CMD ["/app/main"] |
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 ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
"strconv" | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { | |
num1 := r.URL.Query().Get("num1") | |
num2 := r.URL.Query().Get("num2") | |
n1, _ := strconv.Atoi(num1) | |
n2, _ := strconv.Atoi(num2) | |
sum := n1 - n2 // this is show logic error !!! | |
log.Print("Received a request.", "num1=", num1, " num2=", num2, " sum=", sum) | |
fmt.Fprintf(w, "%s+%s=%d\n", num1, num2, sum) | |
} | |
func main() { | |
log.Print("Server started.") | |
http.HandleFunc("/add", handler) | |
port := os.Getenv("PORT") | |
if port == "" { | |
port = "80" | |
} | |
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment