mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
Add shout proxy to example app.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -44,8 +44,6 @@ experimental/genreport/genreport
|
||||
experimental/graphviz/graphviz
|
||||
experimental/oneshot/oneshot
|
||||
experimental/_integration/_integration
|
||||
experimental/example/qotd/qotd
|
||||
experimental/example/goapp/app
|
||||
*sublime-project
|
||||
*sublime-workspace
|
||||
*npm-debug.log
|
||||
|
||||
3
experimental/example/.gitignore
vendored
Normal file
3
experimental/example/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
qotd/qotd
|
||||
goapp/app
|
||||
shout/shout
|
||||
@@ -4,13 +4,17 @@ CFLAGS=-g -lpthread
|
||||
%.o: %.c
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
all: qotd/qotd goapp/app
|
||||
all: qotd/qotd goapp/app shout/shout
|
||||
|
||||
qotd/qotd: qotd/qotd.o
|
||||
gcc -o $@ $< $(CFLAGS)
|
||||
|
||||
goapp/app: goapp/app.go
|
||||
go build -ldflags "-extldflags \"-static\"" -tags netgo -o goapp/app ./goapp
|
||||
shout/shout: shout/shout.go
|
||||
|
||||
shout/shout goapp/app:
|
||||
go get -tags netgo ./$(@D)
|
||||
go build -ldflags "-extldflags \"-static\"" -tags netgo -o $@ ./$(@D)
|
||||
|
||||
clean:
|
||||
rm -f qotd/*.o qotd/qotd goapp/app
|
||||
|
||||
5
experimental/example/shout/Dockerfile
Normal file
5
experimental/example/shout/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM gliderlabs/alpine
|
||||
MAINTAINER Weaveworks Inc <help@weave.works>
|
||||
WORKDIR /home/weave
|
||||
ADD shout /home/weave/
|
||||
ENTRYPOINT ["/home/weave/shout"]
|
||||
62
experimental/example/shout/shout.go
Normal file
62
experimental/example/shout/shout.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
SHOUTCLOUD "github.com/richo/GOSHOUT"
|
||||
)
|
||||
|
||||
type requestResponse struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
var (
|
||||
addr = flag.String("addr", ":8080", "HTTP listen address")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
var req requestResponse
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusTeapot)
|
||||
return
|
||||
}
|
||||
|
||||
req.Text, err = SHOUTCLOUD.UPCASE(req.Text)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusTeapot)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(&req)
|
||||
})
|
||||
|
||||
errc := make(chan error)
|
||||
|
||||
go func() {
|
||||
log.Printf("listening on %s", *addr)
|
||||
errc <- http.ListenAndServe(*addr, nil)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
errc <- interrupt()
|
||||
}()
|
||||
|
||||
log.Printf("%v", <-errc)
|
||||
}
|
||||
|
||||
func interrupt() error {
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||||
return fmt.Errorf("%s", <-c)
|
||||
}
|
||||
Reference in New Issue
Block a user