2021-04-09 01:31:15 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
httpClient "github.com/asim/go-micro/plugins/client/http/v3"
|
2021-10-12 12:55:53 +01:00
|
|
|
"go-micro.dev/v4/client"
|
|
|
|
"go-micro.dev/v4/registry"
|
|
|
|
"go-micro.dev/v4/selector"
|
2021-04-09 01:31:15 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
CallHttpServer()
|
|
|
|
}
|
|
|
|
|
|
|
|
func CallHttpServer() {
|
|
|
|
r := registry.NewRegistry()
|
|
|
|
s := selector.NewSelector(selector.Registry(r))
|
|
|
|
// new client
|
|
|
|
c := httpClient.NewClient(client.Selector(s))
|
|
|
|
// create request/response
|
|
|
|
request := c.NewRequest("demo-http", "/demo", "", client.WithContentType("application/json"))
|
|
|
|
|
|
|
|
response := new(map[string]interface{})
|
|
|
|
// call service
|
|
|
|
err := c.Call(context.Background(), request, response)
|
|
|
|
log.Printf("err:%v response:%#v\n", err, response)
|
|
|
|
|
|
|
|
}
|