diff --git a/Dockerfile b/Dockerfile index b8c0042..1de0b7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,14 @@ -# Start from a Debian image with the latest version of Go installed -# and a workspace (GOPATH) configured at /go. FROM golang # Copy the local package files to the container's workspace. ADD . /go/src/github.com/thrawn01/configmap-microservice-demo -# Build the outyet command inside the container. -# (You may fetch or manage dependencies here, -# either manually or with a tool like "godep".) RUN go get github.com/julienschmidt/httprouter RUN go get gopkg.in/fsnotify.v1 RUN go get gopkg.in/yaml.v2 RUN go install github.com/thrawn01/configmap-microservice-demo -# Run the outyet command by default when the container starts. +# Run the command by default when the container starts. ENTRYPOINT /go/bin/configmap-microservice-demo # Document that the service listens on port 8080. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6fe3c88 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +## How to write configmap enabled golang microservices + +This repo holds code demonstrating how to build a golang service that +reconfigures on the fly when ConfigMap data updates. + +The blog post explaining this code is available +[here](http://thrawn01.org/blog/blog/2016/03/22/howto-write-configmap-enabled-golang-microservices/) + + diff --git a/kubernetes-configmap.yaml b/kubernetes-configmap.yaml index 059dbce..f49dcc0 100644 --- a/kubernetes-configmap.yaml +++ b/kubernetes-configmap.yaml @@ -5,4 +5,4 @@ metadata: namespace: default data: configmap-microservice-demo.yaml: | - message: Hello Grandma + message: Hello World diff --git a/main.go b/main.go index 025180a..1afe859 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,16 @@ func check(err error) { } } +/* + This is the struct that holds our application's configuration +*/ +type Config struct { + Message string `yaml:"message"` +} + +/* + Simple Yaml Config file loader +*/ func loadConfig(configFile string) *Config { conf := &Config{} configData, err := ioutil.ReadFile(configFile) diff --git a/manager.go b/manager.go index 0d52f95..eb88d4a 100644 --- a/manager.go +++ b/manager.go @@ -2,13 +2,6 @@ package main import "sync" -/* - This is the struct that holds our application's configuration -*/ -type Config struct { - Message string `yaml:"message"` -} - /* Simple interface that allows us to switch out both implementations of the Manager */