-
-
Save matisojka/4250285e692944f150b7 to your computer and use it in GitHub Desktop.
A simple microservice plumbing in Go
This file contains 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 google/golang:stable | |
# Godep for vendoring | |
RUN go get github.com/tools/godep | |
# Recompile the standard library without CGO | |
RUN CGO_ENABLED=0 go install -a std | |
MAINTAINER [email protected] | |
ENV APP_DIR $GOPATH/Users/mati/deindeal/moosehead/modules/newsletter_feeds | |
# Set the entrypoint | |
ENTRYPOINT ["/opt/app/newsletter_feeds"] | |
ADD . $APP_DIR | |
# Compile the binary and statically link | |
RUN mkdir /opt/app | |
RUN cd $APP_DIR | |
RUN cd $APP_DIR && godep save | |
RUN cd $APP_DIR && CGO_ENABLED=0 godep go build -o /opt/app/newsletter_feeds -ldflags '-d -w -s' | |
EXPOSE 3001 |
This file contains 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" | |
"io" | |
"log" | |
"net/http" | |
) | |
func helloHandler(res http.ResponseWriter, req *http.Request) { | |
res.Header().Set( | |
"Content-Type", | |
"text/html", | |
) | |
io.WriteString( | |
res, | |
`<doctype html> | |
<html> | |
<head> | |
<title>Hello Gopher</title> | |
</head> | |
<body> | |
Hello Gopher </br> | |
It is really awesome that both Docker and Kubernetes are written in Go! | |
</body> | |
</html>`, | |
) | |
} | |
func defaultHandler(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Go web app powered by Docker") | |
} | |
func main() { | |
http.HandleFunc("/", defaultHandler) | |
http.HandleFunc("/hello", helloHandler) | |
err := http.ListenAndServe(":3001", nil) | |
if err != nil { | |
log.Fatal("ListenAndServe: ", err) | |
return | |
} | |
} |
This file contains 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
docker build -t newsletter_feeds . | |
docker run --rm -p 3001:3001 newsletter_feeds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment