Skip to content

Instantly share code, notes, and snippets.

@asim
Created August 31, 2016 16:25
Show Gist options
  • Save asim/7302dbf99e7f7496b3f55e24cbc1aab0 to your computer and use it in GitHub Desktop.
Save asim/7302dbf99e7f7496b3f55e24cbc1aab0 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"fmt"
"net/http"
"time"
"github.com/pborman/uuid"
"github.com/micro/go-micro/registry"
)
func main() {
id := uuid.NewUUID().String()
service := &registry.Service{
Name: "com.example.srv.foo",
Nodes: []*registry.Node{
&registry.Node{
Id: id,
Address: "127.0.0.1",
Port: 8081,
},
},
}
// init cruft
b, _ := json.Marshal(service)
t := time.NewTicker(time.Second)
buf := bytes.NewBuffer(nil)
// register every second
for _ = range t.C {
buf.Reset()
buf.Write(b)
rsp, err := http.Post("http://localhost:8081/registry?ttl=5s", "application/json", buf)
if err != nil {
fmt.Println(err)
return
}
defer rsp.Body.Close()
ioutil.ReadAll(rsp.Body)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment