1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-30 10:10:44 +02:00

add new services

This commit is contained in:
Asim Aslam 2022-02-16 08:43:36 +00:00
parent 91cfd18373
commit d47c2d984b
9 changed files with 325 additions and 15 deletions

View File

@ -67,7 +67,7 @@ func (t *AppService) Resolve(request *ResolveRequest) (*ResolveResponse, error)
}
// Run an app from a source repo. Specify region etc.
// Run an app from source
func (t *AppService) Run(request *RunRequest) (*RunResponse, error) {
rsp := &RunResponse{}
@ -150,7 +150,7 @@ type ResolveResponse struct {
type RunRequest struct {
// branch. defaults to master
Branch string `json:"branch"`
// associatede env vars to pass in
// associated env vars to pass in
EnvVars map[string]string `json:"env_vars"`
// name of the app
Name string `json:"name"`

View File

@ -5,7 +5,9 @@ import (
)
type Email interface {
Parse(*ParseRequest) (*ParseResponse, error)
Send(*SendRequest) (*SendResponse, error)
Validate(*ValidateRequest) (*ValidateResponse, error)
}
func NewEmailService(token string) *EmailService {
@ -20,6 +22,14 @@ type EmailService struct {
client *client.Client
}
// Parse an RFC5322 address e.g "Joe Blogs <joe@example.com>"
func (t *EmailService) Parse(request *ParseRequest) (*ParseResponse, error) {
rsp := &ParseResponse{}
return rsp, t.client.Call("email", "Parse", request, rsp)
}
// Send an email by passing in from, to, subject, and a text or html body
func (t *EmailService) Send(request *SendRequest) (*SendResponse, error) {
@ -28,6 +38,26 @@ func (t *EmailService) Send(request *SendRequest) (*SendResponse, error) {
}
// Validate an email address format
func (t *EmailService) Validate(request *ValidateRequest) (*ValidateResponse, error) {
rsp := &ValidateResponse{}
return rsp, t.client.Call("email", "Validate", request, rsp)
}
type ParseRequest struct {
// The address to parse. Can be of the format "Joe Blogs <joe@example.com>" or "joe@example.com"
Address string `json:"address"`
}
type ParseResponse struct {
// the email address
Address string `json:"address"`
// associated name e.g Joe Blogs
Name string `json:"name"`
}
type SendRequest struct {
// the display name of the sender
From string `json:"from"`
@ -45,3 +75,11 @@ type SendRequest struct {
type SendResponse struct {
}
type ValidateRequest struct {
Address string `json:"address"`
}
type ValidateResponse struct {
IsValid bool `json:"is_valid"`
}

View File

@ -108,8 +108,13 @@ type Record struct {
}
type SaveRequest struct {
// The file to save
File *Record `json:"file"`
// Make the file public: true or false
Public bool `json:"public"`
}
type SaveResponse struct {
// The permalink for the file if made public
Url string `json:"url"`
}

60
services/minecraft/minecraft.go Executable file
View File

@ -0,0 +1,60 @@
package minecraft
import (
"go-micro.dev/v4/api/client"
)
type Minecraft interface {
Ping(*PingRequest) (*PingResponse, error)
}
func NewMinecraftService(token string) *MinecraftService {
return &MinecraftService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}
type MinecraftService struct {
client *client.Client
}
// Ping a minecraft server
func (t *MinecraftService) Ping(request *PingRequest) (*PingResponse, error) {
rsp := &PingResponse{}
return rsp, t.client.Call("minecraft", "Ping", request, rsp)
}
type PingRequest struct {
// address of the server
Address string `json:"address"`
}
type PingResponse struct {
// Favicon in base64
Favicon string `json:"favicon"`
// Latency (ms) between us and the server (EU)
Latency int32 `json:"latency"`
// Max players ever
MaxPlayers int32 `json:"max_players"`
// Message of the day
Motd string `json:"motd"`
// Number of players online
Players int32 `json:"players"`
// Protocol number of the server
Protocol int32 `json:"protocol"`
// List of connected players
Sample []PlayerSample `json:"sample"`
// Version of the server
Version string `json:"version"`
}
type PlayerSample struct {
// name of the player
Name string `json:"name"`
// unique id of player
Uuid string `json:"uuid"`
}

87
services/ping/ping.go Executable file
View File

@ -0,0 +1,87 @@
package ping
import (
"go-micro.dev/v4/api/client"
)
type Ping interface {
Ip(*IpRequest) (*IpResponse, error)
Tcp(*TcpRequest) (*TcpResponse, error)
Url(*UrlRequest) (*UrlResponse, error)
}
func NewPingService(token string) *PingService {
return &PingService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}
type PingService struct {
client *client.Client
}
// Ping an IP address
func (t *PingService) Ip(request *IpRequest) (*IpResponse, error) {
rsp := &IpResponse{}
return rsp, t.client.Call("ping", "Ip", request, rsp)
}
// Ping a TCP port is open
func (t *PingService) Tcp(request *TcpRequest) (*TcpResponse, error) {
rsp := &TcpResponse{}
return rsp, t.client.Call("ping", "Tcp", request, rsp)
}
// Ping a HTTP URL
func (t *PingService) Url(request *UrlRequest) (*UrlResponse, error) {
rsp := &UrlResponse{}
return rsp, t.client.Call("ping", "Url", request, rsp)
}
type IpRequest struct {
// address to ping
Address string `json:"address"`
}
type IpResponse struct {
// average latency e.g 10ms
Latency string `json:"latency"`
// response status
Status string `json:"status"`
}
type TcpRequest struct {
// address to dial
Address string `json:"address"`
// optional data to send
Data string `json:"data"`
}
type TcpResponse struct {
// response data if any
Data string `json:"data"`
// response status
Status string `json:"status"`
}
type UrlRequest struct {
// address to use
Address string `json:"address"`
// method of the call
Method string `json:"method"`
}
type UrlResponse struct {
// the response code
Code int32 `json:"code"`
// the response status
Status string `json:"status"`
}

103
services/place/place.go Executable file
View File

@ -0,0 +1,103 @@
package place
import (
"go-micro.dev/v4/api/client"
)
type Place interface {
Nearby(*NearbyRequest) (*NearbyResponse, error)
Search(*SearchRequest) (*SearchResponse, error)
}
func NewPlaceService(token string) *PlaceService {
return &PlaceService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}
type PlaceService struct {
client *client.Client
}
// Find places nearby using a location
func (t *PlaceService) Nearby(request *NearbyRequest) (*NearbyResponse, error) {
rsp := &NearbyResponse{}
return rsp, t.client.Call("place", "Nearby", request, rsp)
}
// Search for places by text query
func (t *PlaceService) Search(request *SearchRequest) (*SearchResponse, error) {
rsp := &SearchResponse{}
return rsp, t.client.Call("place", "Search", request, rsp)
}
type AutocompleteRequest struct {
}
type AutocompleteResponse struct {
}
type NearbyRequest struct {
// Keyword to include in the search
Keyword string `json:"keyword"`
// specify the location by lat,lng e.g -33.8670522,-151.1957362
Location string `json:"location"`
// Name of the place to search for
Name string `json:"name"`
// Whether the place is open now
OpenNow bool `json:"open_now"`
// radius in meters within which to search
Radius int32 `json:"radius"`
// Type of place. https://developers.google.com/maps/documentation/places/web-service/supported_types
Type string `json:"type"`
}
type NearbyResponse struct {
Results []Result `json:"results"`
}
type Result struct {
// address of place
Address string `json:"address"`
// url of an icon
IconUrl string `json:"icon_url"`
// lat/lng of place
Location string `json:"location"`
// name of the place
Name string `json:"name"`
// open now
OpenNow bool `json:"open_now"`
// opening hours
OpeningHours string `json:"opening_hours"`
// rating from 1.0 to 5.0
Rating float64 `json:"rating"`
// type of location
Type string `json:"type"`
// feature types
Types []string `json:"types"`
// simplified address
Vicinity string `json:"vicinity"`
}
type SearchRequest struct {
// the location by lat,lng e.g -33.8670522,-151.1957362
Location string `json:"location"`
// Whether the place is open now
OpenNow bool `json:"open_now"`
// the text string on which to search, for example: "restaurant"
Query string `json:"query"`
// radius in meters within which to search
Radius int32 `json:"radius"`
// Type of place. https://developers.google.com/maps/documentation/places/web-service/supported_types
Type string `json:"type"`
}
type SearchResponse struct {
Results []Result `json:"results"`
}

View File

@ -5,6 +5,7 @@ import (
)
type Search interface {
CreateIndex(*CreateIndexRequest) (*CreateIndexResponse, error)
DeleteIndex(*DeleteIndexRequest) (*DeleteIndexResponse, error)
Delete(*DeleteRequest) (*DeleteResponse, error)
Index(*IndexRequest) (*IndexResponse, error)
@ -23,7 +24,15 @@ type SearchService struct {
client *client.Client
}
// Delete an index.
// Create an index by name
func (t *SearchService) CreateIndex(request *CreateIndexRequest) (*CreateIndexResponse, error) {
rsp := &CreateIndexResponse{}
return rsp, t.client.Call("search", "CreateIndex", request, rsp)
}
// Delete an index by name
func (t *SearchService) DeleteIndex(request *DeleteIndexRequest) (*DeleteIndexResponse, error) {
rsp := &DeleteIndexResponse{}
@ -56,8 +65,7 @@ func (t *SearchService) Search(request *SearchRequest) (*SearchResponse, error)
}
type CreateIndexRequest struct {
Fields []Field `json:"fields"`
// the name of the index
// The name of the index
Index string `json:"index"`
}

View File

@ -28,12 +28,15 @@ import (
"go-micro.dev/v4/services/ip"
"go-micro.dev/v4/services/joke"
"go-micro.dev/v4/services/location"
"go-micro.dev/v4/services/minecraft"
"go-micro.dev/v4/services/movie"
"go-micro.dev/v4/services/mq"
"go-micro.dev/v4/services/news"
"go-micro.dev/v4/services/nft"
"go-micro.dev/v4/services/notes"
"go-micro.dev/v4/services/otp"
"go-micro.dev/v4/services/ping"
"go-micro.dev/v4/services/place"
"go-micro.dev/v4/services/postcode"
"go-micro.dev/v4/services/prayer"
"go-micro.dev/v4/services/qr"
@ -90,12 +93,15 @@ func NewClient(token string) *Client {
IpService: ip.NewIpService(token),
JokeService: joke.NewJokeService(token),
LocationService: location.NewLocationService(token),
MinecraftService: minecraft.NewMinecraftService(token),
MovieService: movie.NewMovieService(token),
MqService: mq.NewMqService(token),
NewsService: news.NewNewsService(token),
NftService: nft.NewNftService(token),
NotesService: notes.NewNotesService(token),
OtpService: otp.NewOtpService(token),
PingService: ping.NewPingService(token),
PlaceService: place.NewPlaceService(token),
PostcodeService: postcode.NewPostcodeService(token),
PrayerService: prayer.NewPrayerService(token),
QrService: qr.NewQrService(token),
@ -152,12 +158,15 @@ type Client struct {
IpService *ip.IpService
JokeService *joke.JokeService
LocationService *location.LocationService
MinecraftService *minecraft.MinecraftService
MovieService *movie.MovieService
MqService *mq.MqService
NewsService *news.NewsService
NftService *nft.NftService
NotesService *notes.NotesService
OtpService *otp.OtpService
PingService *ping.PingService
PlaceService *place.PlaceService
PostcodeService *postcode.PostcodeService
PrayerService *prayer.PrayerService
QrService *qr.QrService

View File

@ -116,12 +116,12 @@ func (t *UserService) SendPasswordResetEmail(request *SendPasswordResetEmailRequ
}
// Send a verification email
// to the user being signed up. Email from will be from 'noreply@email.m3ocontent.com',
// but you can provide the title and contents.
// The verification link will be injected in to the email as a template variable, $micro_verification_link.
// Example: 'Hi there, welcome onboard! Use the link below to verify your email: $micro_verification_link'
// The variable will be replaced with an actual url that will look similar to this:
// Send a verification email to a user.
// Email "from" will be 'noreply@email.m3ocontent.com'.
// The verification link will be injected in the email
// as a template variable, $micro_verification_link e.g
// 'Welcome to M3O! Use the link below to verify your email: $micro_verification_link'
// The variable will be replaced with a url similar to:
// 'https://user.m3o.com/user/verify?token=a-verification-token&redirectUrl=your-redir-url'
func (t *UserService) SendVerificationEmail(request *SendVerificationEmailRequest) (*SendVerificationEmailResponse, error) {
@ -316,10 +316,12 @@ type SendPasswordResetEmailResponse struct {
type SendVerificationEmailRequest struct {
// email address to send the verification code
Email string `json:"email"`
Email string `json:"email"`
// The url to redirect to incase of failure
FailureRedirectUrl string `json:"failureRedirectUrl"`
// Display name of the sender for the email. Note: the email address will still be 'noreply@email.m3ocontent.com'
FromName string `json:"fromName"`
FromName string `json:"fromName"`
// The url to redirect to after successful verification
RedirectUrl string `json:"redirectUrl"`
// subject of the email
Subject string `json:"subject"`
@ -371,8 +373,6 @@ type UpdateResponse struct {
}
type VerifyEmailRequest struct {
// the email address to verify
Email string `json:"email"`
// The token from the verification email
Token string `json:"token"`
}