Skip to content

Instantly share code, notes, and snippets.

Created February 22, 2021 09:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Case 2:使用镜像,部署失败 - 逻辑问题查日志定位
# 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
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
# Run service on container startup
FROM alpine:latest
COPY --from=builder /app/main .
CMD ["/app/main"]
package main
import (
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