Skip to content

Commit

Permalink
refactor(demo): slimming down to just demo srv load balancing and not…
Browse files Browse the repository at this point in the history
… confd
  • Loading branch information
benschw committed May 31, 2014
1 parent 6b58e55 commit b72e002
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 43 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ all: build

deps:
go get github.com/miekg/dns
go get launchpad.net/goyaml

build:
go build -o demo
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Build Status](https://drone.io/github.com/benschw/dns-clb-go/status.png)](https://drone.io/github.com/benschw/dns-clb-go/latest)
[![GoDoc](http://godoc.org/github.com/benschw/dns-clb-go?status.png)](http://godoc.org/github.com/benschw/dns-clb-go)

# DNS Client Load Balancer for Go
Expand Down
44 changes: 2 additions & 42 deletions consul_confd_demo.go → demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,11 @@ import (
"fmt"
"github.com/benschw/dns-clb-go/clb"
"io/ioutil"
"launchpad.net/goyaml"
"log"
"net/http"
"os"
)

func status(w http.ResponseWriter, req *http.Request) {
health := "OK"

if _, err := os.Stat("/tmp/fail-healthcheck"); err == nil {
//file exists
health = "FAIL"
}
fmt.Fprintf(w, "%+v", health)
}

// [{"Node":"agent-one","Address":"172.20.20.11","ServiceID":"web","ServiceName":"web","ServiceTags":["rails"],"ServicePort":80}]

func getAddress(svcName string) (string, error) {
c := clb.NewClb("127.0.0.1", "8600", clb.Random)

Expand All @@ -36,41 +23,15 @@ func getAddress(svcName string) (string, error) {
return address.String(), nil
}

type Config struct {
Foo string
Foo2 string
}

func getFoo() (string, error) {
fileData, err := ioutil.ReadFile("/opt/my-config.yaml")
if err != nil {
return "", err
}

data := Config{}

err = goyaml.Unmarshal(fileData, &data)
if err != nil {
return "", err
}
log.Printf("%+v", data)
return data.Foo, nil
}

func foo(w http.ResponseWriter, req *http.Request) {
name, _ := os.Hostname()
foo, err := getFoo()
if err != nil {
log.Print(err)
}

fmt.Fprintf(w, "{\"Name\": \"%s\", \"Foo\": \"%s\"}", name, foo)
fmt.Fprintf(w, "{\"Name\": \"%s\"}", name)

}

type FooName struct {
Name string
Foo string
}

func demo(w http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -98,7 +59,7 @@ func demo(w http.ResponseWriter, req *http.Request) {
log.Fatal(err)
}

fmt.Fprintf(w, "Discovered Address: '%s'\nService Response: Host Name: '%s'\nService Response: Foo: '%s'", addStr, data.Name, data.Foo)
fmt.Fprintf(w, "Discovered Address: '%s'\nService Response: Host Name: '%s'", addStr, data.Name)

}

Expand All @@ -107,7 +68,6 @@ var consulAddr = *flag.String("consul-addr", "localhost:8500", "consul address")

func main() {
flag.Parse()
http.Handle("/status", http.HandlerFunc(status))
http.Handle("/foo", http.HandlerFunc(foo))
http.Handle("/demo", http.HandlerFunc(demo))

Expand Down

0 comments on commit b72e002

Please sign in to comment.