mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Commit from GitHub Actions (Generate Clients & Examples)
This commit is contained in:
@@ -16,36 +16,71 @@ type StreamService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Publish a message to the stream. Specify a topic to group messages for a specific topic.
|
||||
func (t *StreamService) Publish(request *PublishRequest) (*PublishResponse, error) {
|
||||
rsp := &PublishResponse{}
|
||||
return rsp, t.client.Call("stream", "Publish", request, rsp)
|
||||
// List all the active channels
|
||||
func (t *StreamService) ListChannels(request *ListChannelsRequest) (*ListChannelsResponse, error) {
|
||||
rsp := &ListChannelsResponse{}
|
||||
return rsp, t.client.Call("stream", "ListChannels", request, rsp)
|
||||
}
|
||||
|
||||
// Subscribe to messages for a given topic.
|
||||
func (t *StreamService) Subscribe(request *SubscribeRequest) (*SubscribeResponse, error) {
|
||||
rsp := &SubscribeResponse{}
|
||||
return rsp, t.client.Call("stream", "Subscribe", request, rsp)
|
||||
// List messages for a given channel
|
||||
func (t *StreamService) ListMessages(request *ListMessagesRequest) (*ListMessagesResponse, error) {
|
||||
rsp := &ListMessagesResponse{}
|
||||
return rsp, t.client.Call("stream", "ListMessages", request, rsp)
|
||||
}
|
||||
|
||||
type PublishRequest struct {
|
||||
// The json message to publish
|
||||
Message map[string]interface{} `json:"message"`
|
||||
// The topic to publish to
|
||||
Topic string `json:"topic"`
|
||||
// SendMessage a message to the stream.
|
||||
func (t *StreamService) SendMessage(request *SendMessageRequest) (*SendMessageResponse, error) {
|
||||
rsp := &SendMessageResponse{}
|
||||
return rsp, t.client.Call("stream", "SendMessage", request, rsp)
|
||||
}
|
||||
|
||||
type PublishResponse struct {
|
||||
type Channel struct {
|
||||
// last activity time
|
||||
LastActive string `json:"lastActive"`
|
||||
// name of the channel
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type SubscribeRequest struct {
|
||||
// The topic to subscribe to
|
||||
Topic string `json:"topic"`
|
||||
type ListChannelsRequest struct {
|
||||
}
|
||||
|
||||
type SubscribeResponse struct {
|
||||
// The next json message on the topic
|
||||
Message map[string]interface{} `json:"message"`
|
||||
// The topic subscribed to
|
||||
Topic string `json:"topic"`
|
||||
type ListChannelsResponse struct {
|
||||
Channels []Channel `json:"channels"`
|
||||
}
|
||||
|
||||
type ListMessagesRequest struct {
|
||||
// The channel to subscribe to
|
||||
Channel string `json:"channel"`
|
||||
// number of message to return
|
||||
Limit int32 `json:"limit"`
|
||||
}
|
||||
|
||||
type ListMessagesResponse struct {
|
||||
// The channel subscribed to
|
||||
Channel string `json:"channel"`
|
||||
// Messages are chronological order
|
||||
Messages []Message `json:"messages"`
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
// the channel name
|
||||
Channel string `json:"channel"`
|
||||
// id of the message
|
||||
Id string `json:"id"`
|
||||
// the associated metadata
|
||||
Metadata map[string]string `json:"metadata"`
|
||||
// text of the message
|
||||
Text string `json:"text"`
|
||||
// time of message creation
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
|
||||
type SendMessageRequest struct {
|
||||
// The channel to send to
|
||||
Channel string `json:"channel"`
|
||||
// The message text to send
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type SendMessageResponse struct {
|
||||
}
|
||||
|
||||
@@ -78,5 +78,5 @@
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"version": "1.0.615"
|
||||
"version": "1.0.618"
|
||||
}
|
||||
@@ -12,10 +12,10 @@ func CreateArecord() {
|
||||
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := dbService.Create(&db.CreateRequest{
|
||||
Record: map[string]interface{}{
|
||||
"id": "1",
|
||||
"name": "Jane",
|
||||
"age": 42,
|
||||
"isActive": true,
|
||||
"id": "1",
|
||||
"name": "Jane",
|
||||
},
|
||||
Table: "users",
|
||||
})
|
||||
|
||||
4
examples/stream/listChannels/curl/listChannels.sh
Executable file
4
examples/stream/listChannels/curl/listChannels.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
curl "https://api.m3o.com/v1/stream/ListChannels" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{}'
|
||||
15
examples/stream/listChannels/go/listChannels.go
Executable file
15
examples/stream/listChannels/go/listChannels.go
Executable file
@@ -0,0 +1,15 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/micro/services/clients/go/stream"
|
||||
)
|
||||
|
||||
// List all the active channels
|
||||
func ListChannels() {
|
||||
streamService := stream.NewStreamService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := streamService.ListChannels(&stream.ListChannelsRequest{})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
10
examples/stream/listChannels/node/listChannels.js
Executable file
10
examples/stream/listChannels/node/listChannels.js
Executable file
@@ -0,0 +1,10 @@
|
||||
const { StreamService } = require("m3o/stream");
|
||||
|
||||
// List all the active channels
|
||||
async function listChannels() {
|
||||
let streamService = new StreamService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await streamService.listChannels({});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
listChannels();
|
||||
6
examples/stream/listMessages/curl/listMessages.sh
Executable file
6
examples/stream/listMessages/curl/listMessages.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/stream/ListMessages" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"channel": "general"
|
||||
}'
|
||||
17
examples/stream/listMessages/go/listMessages.go
Executable file
17
examples/stream/listMessages/go/listMessages.go
Executable file
@@ -0,0 +1,17 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/micro/services/clients/go/stream"
|
||||
)
|
||||
|
||||
// List messages for a given channel
|
||||
func ListMessages() {
|
||||
streamService := stream.NewStreamService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := streamService.ListMessages(&stream.ListMessagesRequest{
|
||||
Channel: "general",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/stream/listMessages/node/listMessages.js
Executable file
12
examples/stream/listMessages/node/listMessages.js
Executable file
@@ -0,0 +1,12 @@
|
||||
const { StreamService } = require("m3o/stream");
|
||||
|
||||
// List messages for a given channel
|
||||
async function listMessages() {
|
||||
let streamService = new StreamService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await streamService.listMessages({
|
||||
channel: "general",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
listMessages();
|
||||
7
examples/stream/sendMessage/curl/sendAMessage.sh
Executable file
7
examples/stream/sendMessage/curl/sendAMessage.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
curl "https://api.m3o.com/v1/stream/SendMessage" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"channel": "general",
|
||||
"text": "Hey checkout this tweet https://twitter.com/m3oservices/status/1455291054295498752"
|
||||
}'
|
||||
18
examples/stream/sendMessage/go/sendAMessage.go
Executable file
18
examples/stream/sendMessage/go/sendAMessage.go
Executable file
@@ -0,0 +1,18 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/micro/services/clients/go/stream"
|
||||
)
|
||||
|
||||
// SendMessage a message to the stream.
|
||||
func SendAmessage() {
|
||||
streamService := stream.NewStreamService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := streamService.SendMessage(&stream.SendMessageRequest{
|
||||
Channel: "general",
|
||||
Text: "Hey checkout this tweet https://twitter.com/m3oservices/status/1455291054295498752",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
13
examples/stream/sendMessage/node/sendAMessage.js
Executable file
13
examples/stream/sendMessage/node/sendAMessage.js
Executable file
@@ -0,0 +1,13 @@
|
||||
const { StreamService } = require("m3o/stream");
|
||||
|
||||
// SendMessage a message to the stream.
|
||||
async function sendAmessage() {
|
||||
let streamService = new StreamService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await streamService.sendMessage({
|
||||
channel: "general",
|
||||
text: "Hey checkout this tweet https://twitter.com/m3oservices/status/1455291054295498752",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
sendAmessage();
|
||||
Reference in New Issue
Block a user