Skip to content

Instantly share code, notes, and snippets.

@Formergg
Created March 11, 2021 04:26
Show Gist options
  • Save Formergg/ddde2d9aebd66d59a8482d65768a916c to your computer and use it in GitHub Desktop.
Save Formergg/ddde2d9aebd66d59a8482d65768a916c to your computer and use it in GitHub Desktop.
标准输出日志示例代码
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {
target := "Welcome to CloudBase"
fmt.Fprintf(w, "Hello, %s!\n", target)
fmt.Println("receive a request, this is [stdout] log")
}
func main() {
http.HandleFunc("/", handler)
port := os.Getenv("PORT")
if port == "" {
port = "80"
}
fmt.Fprint(os.Stdout, "start service, this is [stdout] log\n")
fmt.Fprint(os.Stderr, "start service, this is [stderr] log\n")
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}
# 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"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment