Skip to content

Instantly share code, notes, and snippets.

@Formergg
Created February 22, 2021 09:02
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 Formergg/d6ba43f0a943475e302abb32d04821f4 to your computer and use it in GitHub Desktop.
Save Formergg/d6ba43f0a943475e302abb32d04821f4 to your computer and use it in GitHub Desktop.
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
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"]
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