Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created February 23, 2019 18:55
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 arriqaaq/5eb5e7d63d04ac73f1c4f2d276a279d8 to your computer and use it in GitHub Desktop.
Save arriqaaq/5eb5e7d63d04ac73f1c4f2d276a279d8 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/arriqaaq/boomerang"
lucio "github.com/arriqaaq/server"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
"os"
"strings"
"time"
)
const (
URL_SERVICE_B = "http://0.0.0.0:8081/pong"
)
var (
clientCnf = &boomerang.ClientConfig{
RecordMetrics: true,
MetricNamespace: "service_a",
Transport: boomerang.DefaultTransport(),
Backoff: boomerang.NewConstantBackoff(100 * time.Millisecond),
MaxRetries: 1,
}
)
func main() {
client := boomerang.NewHttpClient(clientCnf)
mux := http.NewServeMux()
mux.HandleFunc("/ping", func(w http.ResponseWriter, req *http.Request) {
request, _ := http.NewRequest("GET", URL_SERVICE_B, strings.NewReader("gopher"))
resp, httpErr := client.Do(request)
if httpErr != nil {
fmt.Println("ping failed ", httpErr)
w.Write([]byte("fail"))
return
}
defer resp.Body.Close()
w.Write([]byte("pong"))
return
})
mux.Handle("/metrics", promhttp.Handler())
server := lucio.NewServer(mux, "0.0.0.0", 8089)
err := server.Serve()
log.Println("terminated", os.Getpid(), err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment