Merge branch 'master' of ssh://github.com/m3o/m3o-go

This commit is contained in:
Asim Aslam
2021-04-21 16:08:13 +01:00

View File

@@ -1,6 +1,8 @@
# M3O Go Client # M3O Go Client
By default the client connects to api.m3o.com/client This is the Go client to access APIs on the M3O Platform
## Usage
```go ```go
package main package main
@@ -33,28 +35,18 @@ func main() {
req := &Request{ req := &Request{
Name: "John", Name: "John",
} }
var rsp Response var rsp Response
if err := c.Call("greeter", "Say.Hello", req, &rsp); err != nil { if err := c.Call("helloworld", "call", req, &rsp); err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
fmt.Println(rsp) fmt.Println(rsp)
} }
``` ```
If you want to access your local micro:
```go
c := client.NewClient(client.Options{Local: true})
```
You can also set the api address explicitly:
```go
c := client.NewClient(client.Options{Address: "https://api.yourdomain.com/client"})
```
## Streaming ## Streaming
The client supports streaming The client supports streaming
@@ -76,10 +68,17 @@ type Response struct {
Count string `json:"count"` Count string `json:"count"`
} }
func main() { var (
c := client.NewClient(&client.Options{Local: true}) token, _ = os.Getenv("TOKEN")
)
stream, err := c.Stream("example", "Streamer.ServerStream", Request{Count: "10"}) func main() {
c := client.NewClient(nil)
// set your api token
c.SetToken(token)
stream, err := c.Stream("streams", "subscribe", Request{Count: "10"})
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return