mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-18 05:05:14 +00:00
Commit from m3o/m3o action
This commit is contained in:
@@ -4,6 +4,33 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Event/api](htt
|
||||
|
||||
Endpoints:
|
||||
|
||||
## Read
|
||||
|
||||
Read stored events
|
||||
|
||||
|
||||
[https://m3o.com/event/api#Read](https://m3o.com/event/api#Read)
|
||||
|
||||
```go
|
||||
package example
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"go.m3o.com/event"
|
||||
)
|
||||
|
||||
// Read stored events
|
||||
func ReadEventsOnAtopic() {
|
||||
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||
rsp, err := eventService.Read(&event.ReadRequest{
|
||||
Topic: "user",
|
||||
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
```
|
||||
## Publish
|
||||
|
||||
Publish a event to the event stream.
|
||||
@@ -63,30 +90,3 @@ func ConsumeFromAtopic() {
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
```
|
||||
## Read
|
||||
|
||||
Read stored events
|
||||
|
||||
|
||||
[https://m3o.com/event/api#Read](https://m3o.com/event/api#Read)
|
||||
|
||||
```go
|
||||
package example
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"go.m3o.com/event"
|
||||
)
|
||||
|
||||
// Read stored events
|
||||
func ReadEventsOnAtopic() {
|
||||
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||
rsp, err := eventService.Read(&event.ReadRequest{
|
||||
Topic: "user",
|
||||
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -10,8 +10,22 @@ import (
|
||||
// Consume events from a given topic.
|
||||
func main() {
|
||||
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||
rsp, err := eventService.Consume(&event.ConsumeRequest{
|
||||
|
||||
stream, err := eventService.Consume(&event.ConsumeRequest{
|
||||
Topic: "user",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
for {
|
||||
rsp, err := stream.Recv()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(rsp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,5 @@ func main() {
|
||||
Topic: "user",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
|
||||
}
|
||||
|
||||
@@ -14,4 +14,5 @@ func main() {
|
||||
Topic: "user",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user