Skip to content

Instantly share code, notes, and snippets.

@matisojka
Forked from shijuvar/main.go
Last active March 5, 2016 09:23
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 matisojka/4250285e692944f150b7 to your computer and use it in GitHub Desktop.
Save matisojka/4250285e692944f150b7 to your computer and use it in GitHub Desktop.
A simple microservice plumbing in Go
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 mateusz.sojka@deindeal.ch
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
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
}
}
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