Created
August 31, 2016 16:25
-
-
Save asim/7302dbf99e7f7496b3f55e24cbc1aab0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 := ®istry.Service{ | |
Name: "com.example.srv.foo", | |
Nodes: []*registry.Node{ | |
®istry.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