mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-22 07:15:25 +00:00
Commit from GitHub Actions (Generate Clients & Examples)
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/micro/services/clients/go/image"
|
"github.com/micro/services/clients/go/image"
|
||||||
"github.com/micro/services/clients/go/ip"
|
"github.com/micro/services/clients/go/ip"
|
||||||
"github.com/micro/services/clients/go/location"
|
"github.com/micro/services/clients/go/location"
|
||||||
|
"github.com/micro/services/clients/go/mq"
|
||||||
"github.com/micro/services/clients/go/notes"
|
"github.com/micro/services/clients/go/notes"
|
||||||
"github.com/micro/services/clients/go/otp"
|
"github.com/micro/services/clients/go/otp"
|
||||||
"github.com/micro/services/clients/go/postcode"
|
"github.com/micro/services/clients/go/postcode"
|
||||||
@@ -72,6 +73,7 @@ func NewClient(token string) *Client {
|
|||||||
ImageService: image.NewImageService(token),
|
ImageService: image.NewImageService(token),
|
||||||
IpService: ip.NewIpService(token),
|
IpService: ip.NewIpService(token),
|
||||||
LocationService: location.NewLocationService(token),
|
LocationService: location.NewLocationService(token),
|
||||||
|
MqService: mq.NewMqService(token),
|
||||||
NotesService: notes.NewNotesService(token),
|
NotesService: notes.NewNotesService(token),
|
||||||
OtpService: otp.NewOtpService(token),
|
OtpService: otp.NewOtpService(token),
|
||||||
PostcodeService: postcode.NewPostcodeService(token),
|
PostcodeService: postcode.NewPostcodeService(token),
|
||||||
@@ -121,6 +123,7 @@ type Client struct {
|
|||||||
ImageService *image.ImageService
|
ImageService *image.ImageService
|
||||||
IpService *ip.IpService
|
IpService *ip.IpService
|
||||||
LocationService *location.LocationService
|
LocationService *location.LocationService
|
||||||
|
MqService *mq.MqService
|
||||||
NotesService *notes.NotesService
|
NotesService *notes.NotesService
|
||||||
OtpService *otp.OtpService
|
OtpService *otp.OtpService
|
||||||
PostcodeService *postcode.PostcodeService
|
PostcodeService *postcode.PostcodeService
|
||||||
|
|||||||
51
clients/go/mq/mq.go
Executable file
51
clients/go/mq/mq.go
Executable file
@@ -0,0 +1,51 @@
|
|||||||
|
package mq
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/m3o/m3o-go/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewMqService(token string) *MqService {
|
||||||
|
return &MqService{
|
||||||
|
client: client.NewClient(&client.Options{
|
||||||
|
Token: token,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MqService struct {
|
||||||
|
client *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish a message to the mq. Specify a topic to group messages for a specific topic.
|
||||||
|
func (t *MqService) Publish(request *PublishRequest) (*PublishResponse, error) {
|
||||||
|
rsp := &PublishResponse{}
|
||||||
|
return rsp, t.client.Call("mq", "Publish", request, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subscribe to messages for a given topic.
|
||||||
|
func (t *MqService) Subscribe(request *SubscribeRequest) (*SubscribeResponse, error) {
|
||||||
|
rsp := &SubscribeResponse{}
|
||||||
|
return rsp, t.client.Call("mq", "Subscribe", 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PublishResponse struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscribeRequest struct {
|
||||||
|
// The topic to subscribe to
|
||||||
|
Topic string `json:"topic"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscribeResponse struct {
|
||||||
|
// The next json message on the topic
|
||||||
|
Message map[string]interface{} `json:"message"`
|
||||||
|
// The topic subscribed to
|
||||||
|
Topic string `json:"topic"`
|
||||||
|
}
|
||||||
1
clients/ts/.gitignore
vendored
1
clients/ts/.gitignore
vendored
@@ -34,6 +34,7 @@ id
|
|||||||
image
|
image
|
||||||
ip
|
ip
|
||||||
location
|
location
|
||||||
|
mq
|
||||||
notes
|
notes
|
||||||
otp
|
otp
|
||||||
pkg
|
pkg
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import * as id from "./id";
|
|||||||
import * as image from "./image";
|
import * as image from "./image";
|
||||||
import * as ip from "./ip";
|
import * as ip from "./ip";
|
||||||
import * as location from "./location";
|
import * as location from "./location";
|
||||||
|
import * as mq from "./mq";
|
||||||
import * as notes from "./notes";
|
import * as notes from "./notes";
|
||||||
import * as otp from "./otp";
|
import * as otp from "./otp";
|
||||||
import * as postcode from "./postcode";
|
import * as postcode from "./postcode";
|
||||||
@@ -66,6 +67,7 @@ export class Client {
|
|||||||
this.imageService = new image.ImageService(token);
|
this.imageService = new image.ImageService(token);
|
||||||
this.ipService = new ip.IpService(token);
|
this.ipService = new ip.IpService(token);
|
||||||
this.locationService = new location.LocationService(token);
|
this.locationService = new location.LocationService(token);
|
||||||
|
this.mqService = new mq.MqService(token);
|
||||||
this.notesService = new notes.NotesService(token);
|
this.notesService = new notes.NotesService(token);
|
||||||
this.otpService = new otp.OtpService(token);
|
this.otpService = new otp.OtpService(token);
|
||||||
this.postcodeService = new postcode.PostcodeService(token);
|
this.postcodeService = new postcode.PostcodeService(token);
|
||||||
@@ -111,6 +113,7 @@ export class Client {
|
|||||||
imageService: image.ImageService;
|
imageService: image.ImageService;
|
||||||
ipService: ip.IpService;
|
ipService: ip.IpService;
|
||||||
locationService: location.LocationService;
|
locationService: location.LocationService;
|
||||||
|
mqService: mq.MqService;
|
||||||
notesService: notes.NotesService;
|
notesService: notes.NotesService;
|
||||||
otpService: otp.OtpService;
|
otpService: otp.OtpService;
|
||||||
postcodeService: postcode.PostcodeService;
|
postcodeService: postcode.PostcodeService;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
"image",
|
"image",
|
||||||
"ip",
|
"ip",
|
||||||
"location",
|
"location",
|
||||||
|
"mq",
|
||||||
"notes",
|
"notes",
|
||||||
"otp",
|
"otp",
|
||||||
"pkg",
|
"pkg",
|
||||||
@@ -77,5 +78,5 @@
|
|||||||
"prepare": "npm run build"
|
"prepare": "npm run build"
|
||||||
},
|
},
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"version": "1.0.600"
|
"version": "1.0.601"
|
||||||
}
|
}
|
||||||
@@ -12,10 +12,10 @@ func CreateArecord() {
|
|||||||
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
rsp, err := dbService.Create(&db.CreateRequest{
|
rsp, err := dbService.Create(&db.CreateRequest{
|
||||||
Record: map[string]interface{}{
|
Record: map[string]interface{}{
|
||||||
"age": 42,
|
|
||||||
"isActive": true,
|
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"name": "Jane",
|
"name": "Jane",
|
||||||
|
"age": 42,
|
||||||
|
"isActive": true,
|
||||||
},
|
},
|
||||||
Table: "users",
|
Table: "users",
|
||||||
})
|
})
|
||||||
|
|||||||
11
examples/mq/publish/curl/publishAMessage.sh
Executable file
11
examples/mq/publish/curl/publishAMessage.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
curl "https://api.m3o.com/v1/mq/Publish" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||||
|
-d '{
|
||||||
|
"message": {
|
||||||
|
"id": "1",
|
||||||
|
"type": "signup",
|
||||||
|
"user": "john"
|
||||||
|
},
|
||||||
|
"topic": "events"
|
||||||
|
}'
|
||||||
22
examples/mq/publish/go/publishAMessage.go
Executable file
22
examples/mq/publish/go/publishAMessage.go
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/micro/services/clients/go/mq"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Publish a message to the mq. Specify a topic to group messages for a specific topic.
|
||||||
|
func PublishAmessage() {
|
||||||
|
mqService := mq.NewMqService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
|
rsp, err := mqService.Publish(&mq.PublishRequest{
|
||||||
|
Message: map[string]interface{}{
|
||||||
|
"id": "1",
|
||||||
|
"type": "signup",
|
||||||
|
"user": "john",
|
||||||
|
},
|
||||||
|
Topic: "events",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/mq/publish/node/publishAMessage.js
Executable file
17
examples/mq/publish/node/publishAMessage.js
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
const { MqService } = require("m3o/mq");
|
||||||
|
|
||||||
|
// Publish a message to the mq. Specify a topic to group messages for a specific topic.
|
||||||
|
async function publishAmessage() {
|
||||||
|
let mqService = new MqService(process.env.MICRO_API_TOKEN);
|
||||||
|
let rsp = await mqService.publish({
|
||||||
|
message: {
|
||||||
|
id: "1",
|
||||||
|
type: "signup",
|
||||||
|
user: "john",
|
||||||
|
},
|
||||||
|
topic: "events",
|
||||||
|
});
|
||||||
|
console.log(rsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
publishAmessage();
|
||||||
6
examples/mq/subscribe/curl/subscribeToATopic.sh
Executable file
6
examples/mq/subscribe/curl/subscribeToATopic.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
curl "https://api.m3o.com/v1/mq/Subscribe" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||||
|
-d '{
|
||||||
|
"topic": "events"
|
||||||
|
}'
|
||||||
17
examples/mq/subscribe/go/subscribeToATopic.go
Executable file
17
examples/mq/subscribe/go/subscribeToATopic.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/micro/services/clients/go/mq"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Subscribe to messages for a given topic.
|
||||||
|
func SubscribeToAtopic() {
|
||||||
|
mqService := mq.NewMqService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
|
rsp, err := mqService.Subscribe(&mq.SubscribeRequest{
|
||||||
|
Topic: "events",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
12
examples/mq/subscribe/node/subscribeToATopic.js
Executable file
12
examples/mq/subscribe/node/subscribeToATopic.js
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
const { MqService } = require("m3o/mq");
|
||||||
|
|
||||||
|
// Subscribe to messages for a given topic.
|
||||||
|
async function subscribeToAtopic() {
|
||||||
|
let mqService = new MqService(process.env.MICRO_API_TOKEN);
|
||||||
|
let rsp = await mqService.subscribe({
|
||||||
|
topic: "events",
|
||||||
|
});
|
||||||
|
console.log(rsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribeToAtopic();
|
||||||
@@ -12,9 +12,9 @@ func PublishAmessage() {
|
|||||||
streamService := stream.NewStreamService(os.Getenv("MICRO_API_TOKEN"))
|
streamService := stream.NewStreamService(os.Getenv("MICRO_API_TOKEN"))
|
||||||
rsp, err := streamService.Publish(&stream.PublishRequest{
|
rsp, err := streamService.Publish(&stream.PublishRequest{
|
||||||
Message: map[string]interface{}{
|
Message: map[string]interface{}{
|
||||||
|
"user": "john",
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"type": "signup",
|
"type": "signup",
|
||||||
"user": "john",
|
|
||||||
},
|
},
|
||||||
Topic: "events",
|
Topic: "events",
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user