Created
November 3, 2017 16:33
-
-
Save raphink/19f883f86abb3866a0331f52847c1362 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
This file contains hidden or 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" | |
"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