Skip to content

Instantly share code, notes, and snippets.

@raphink
Created November 3, 2017 16:33
Show Gist options
  • Save raphink/19f883f86abb3866a0331f52847c1362 to your computer and use it in GitHub Desktop.
Save raphink/19f883f86abb3866a0331f52847c1362 to your computer and use it in GitHub Desktop.
FROM golang:1.9 as builder
COPY main.go /tmp
RUN cd /tmp && \
go get -d github.com/Sirupsen/logrus && \
CGO_ENABLED=0 GOOS=linux \
go build -a \
-installsuffix cgo -o entrypoint main.go
FROM scratch
COPY --from=builder /tmp/entrypoint /entrypoint
ENTRYPOINT [ "/entrypoint" ]
EXPOSE 8080
package main
import (
"fmt"
"net/http"
"github.com/Sirupsen/logrus"
)
type student struct {
Name string
Age int
}
func handler(w http.ResponseWriter, r *http.Request) {
s := student{
Name: "Foo",
Age: 42,
}
logrus.Debugf("Printing info on student %s", s.Name)
fmt.Fprintf(w, "<h1>hello, %s</h1><br />You are %v years old.\n", s.Name, s.Age)
}
func main() {
http.HandleFunc("/", handler)
logrus.Info("Listening on port 8080")
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment