mirror of
https://github.com/go-micro/go-micro.git
synced 2025-01-05 10:20:53 +02:00
add service updates (#2418)
This commit is contained in:
parent
23f1de80c5
commit
9e0be6c85d
16
services/cache/cache.go
vendored
16
services/cache/cache.go
vendored
@ -9,6 +9,7 @@ type Cache interface {
|
|||||||
Delete(*DeleteRequest) (*DeleteResponse, error)
|
Delete(*DeleteRequest) (*DeleteResponse, error)
|
||||||
Get(*GetRequest) (*GetResponse, error)
|
Get(*GetRequest) (*GetResponse, error)
|
||||||
Increment(*IncrementRequest) (*IncrementResponse, error)
|
Increment(*IncrementRequest) (*IncrementResponse, error)
|
||||||
|
ListKeys(*ListKeysRequest) (*ListKeysResponse, error)
|
||||||
Set(*SetRequest) (*SetResponse, error)
|
Set(*SetRequest) (*SetResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +57,14 @@ func (t *CacheService) Increment(request *IncrementRequest) (*IncrementResponse,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List all the available keys
|
||||||
|
func (t *CacheService) ListKeys(request *ListKeysRequest) (*ListKeysResponse, error) {
|
||||||
|
|
||||||
|
rsp := &ListKeysResponse{}
|
||||||
|
return rsp, t.client.Call("cache", "ListKeys", request, rsp)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Set an item in the cache. Overwrites any existing value already set.
|
// Set an item in the cache. Overwrites any existing value already set.
|
||||||
func (t *CacheService) Set(request *SetRequest) (*SetResponse, error) {
|
func (t *CacheService) Set(request *SetRequest) (*SetResponse, error) {
|
||||||
|
|
||||||
@ -116,6 +125,13 @@ type IncrementResponse struct {
|
|||||||
Value int64 `json:"value,string"`
|
Value int64 `json:"value,string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListKeysRequest struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListKeysResponse struct {
|
||||||
|
Keys []string `json:"keys"`
|
||||||
|
}
|
||||||
|
|
||||||
type SetRequest struct {
|
type SetRequest struct {
|
||||||
// The key to update
|
// The key to update
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
52
services/carbon/carbon.go
Executable file
52
services/carbon/carbon.go
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
package carbon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-micro.dev/v4/api/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Carbon interface {
|
||||||
|
Offset(*OffsetRequest) (*OffsetResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCarbonService(token string) *CarbonService {
|
||||||
|
return &CarbonService{
|
||||||
|
client: client.NewClient(&client.Options{
|
||||||
|
Token: token,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type CarbonService struct {
|
||||||
|
client *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Purchase 1KG (0.001 tonne) of carbon offsets in a single request
|
||||||
|
func (t *CarbonService) Offset(request *OffsetRequest) (*OffsetResponse, error) {
|
||||||
|
|
||||||
|
rsp := &OffsetResponse{}
|
||||||
|
return rsp, t.client.Call("carbon", "Offset", request, rsp)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type OffsetRequest struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type OffsetResponse struct {
|
||||||
|
// the metric used e.g KG or Tonnes
|
||||||
|
Metric string `json:"metric"`
|
||||||
|
// projects it was allocated to
|
||||||
|
Projects []Project `json:"projects"`
|
||||||
|
// number of tonnes
|
||||||
|
Tonnes float64 `json:"tonnes"`
|
||||||
|
// number of units purchased
|
||||||
|
Units int32 `json:"units"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Project struct {
|
||||||
|
// name of the project
|
||||||
|
Name string `json:"name"`
|
||||||
|
// percentage that went to this
|
||||||
|
Percentage float64 `json:"percentage"`
|
||||||
|
// amount in tonnes
|
||||||
|
Tonnes float64 `json:"tonnes"`
|
||||||
|
}
|
@ -5,7 +5,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Search interface {
|
type Search interface {
|
||||||
Vote(*VoteRequest) (*VoteResponse, error)
|
DeleteIndex(*DeleteIndexRequest) (*DeleteIndexResponse, error)
|
||||||
|
Delete(*DeleteRequest) (*DeleteResponse, error)
|
||||||
|
Index(*IndexRequest) (*IndexResponse, error)
|
||||||
|
Search(*SearchRequest) (*SearchResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSearchService(token string) *SearchService {
|
func NewSearchService(token string) *SearchService {
|
||||||
@ -20,20 +23,98 @@ type SearchService struct {
|
|||||||
client *client.Client
|
client *client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vote to have the Search api launched faster!
|
// Delete an index.
|
||||||
func (t *SearchService) Vote(request *VoteRequest) (*VoteResponse, error) {
|
func (t *SearchService) DeleteIndex(request *DeleteIndexRequest) (*DeleteIndexResponse, error) {
|
||||||
|
|
||||||
rsp := &VoteResponse{}
|
rsp := &DeleteIndexResponse{}
|
||||||
return rsp, t.client.Call("search", "Vote", request, rsp)
|
return rsp, t.client.Call("search", "DeleteIndex", request, rsp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type VoteRequest struct {
|
// Delete a document given its ID
|
||||||
// optional message
|
func (t *SearchService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
||||||
Message string `json:"message"`
|
|
||||||
|
rsp := &DeleteResponse{}
|
||||||
|
return rsp, t.client.Call("search", "Delete", request, rsp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type VoteResponse struct {
|
// Index a document i.e. insert a document to search for.
|
||||||
// response message
|
func (t *SearchService) Index(request *IndexRequest) (*IndexResponse, error) {
|
||||||
Message string `json:"message"`
|
|
||||||
|
rsp := &IndexResponse{}
|
||||||
|
return rsp, t.client.Call("search", "Index", request, rsp)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search for documents in a given in index
|
||||||
|
func (t *SearchService) Search(request *SearchRequest) (*SearchResponse, error) {
|
||||||
|
|
||||||
|
rsp := &SearchResponse{}
|
||||||
|
return rsp, t.client.Call("search", "Search", request, rsp)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateIndexRequest struct {
|
||||||
|
Fields []Field `json:"fields"`
|
||||||
|
// the name of the index
|
||||||
|
Index string `json:"index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateIndexResponse struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteIndexRequest struct {
|
||||||
|
// The name of the index to delete
|
||||||
|
Index string `json:"index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteIndexResponse struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteRequest struct {
|
||||||
|
// The ID of the document to delete
|
||||||
|
Id string `json:"id"`
|
||||||
|
// The index the document belongs to
|
||||||
|
Index string `json:"index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteResponse struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type Document struct {
|
||||||
|
// The JSON contents of the document
|
||||||
|
Contents map[string]interface{} `json:"contents"`
|
||||||
|
// The ID for this document. If blank, one will be generated
|
||||||
|
Id string `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Field struct {
|
||||||
|
// The name of the field. Use a `.` separator to define nested fields e.g. foo.bar
|
||||||
|
Name string `json:"name"`
|
||||||
|
// The type of the field - string, number
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type IndexRequest struct {
|
||||||
|
// The document to index
|
||||||
|
Document *Document `json:"document"`
|
||||||
|
// The index this document belongs to
|
||||||
|
Index string `json:"index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type IndexResponse struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchRequest struct {
|
||||||
|
// The index the document belongs to
|
||||||
|
Index string `json:"index"`
|
||||||
|
// The query. See docs for query language examples
|
||||||
|
Query string `json:"query"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchResponse struct {
|
||||||
|
// The matching documents
|
||||||
|
Documents []Document `json:"documents"`
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"go-micro.dev/v4/services/app"
|
"go-micro.dev/v4/services/app"
|
||||||
"go-micro.dev/v4/services/avatar"
|
"go-micro.dev/v4/services/avatar"
|
||||||
"go-micro.dev/v4/services/cache"
|
"go-micro.dev/v4/services/cache"
|
||||||
|
"go-micro.dev/v4/services/carbon"
|
||||||
"go-micro.dev/v4/services/contact"
|
"go-micro.dev/v4/services/contact"
|
||||||
"go-micro.dev/v4/services/crypto"
|
"go-micro.dev/v4/services/crypto"
|
||||||
"go-micro.dev/v4/services/currency"
|
"go-micro.dev/v4/services/currency"
|
||||||
@ -67,6 +68,7 @@ func NewClient(token string) *Client {
|
|||||||
AppService: app.NewAppService(token),
|
AppService: app.NewAppService(token),
|
||||||
AvatarService: avatar.NewAvatarService(token),
|
AvatarService: avatar.NewAvatarService(token),
|
||||||
CacheService: cache.NewCacheService(token),
|
CacheService: cache.NewCacheService(token),
|
||||||
|
CarbonService: carbon.NewCarbonService(token),
|
||||||
ContactService: contact.NewContactService(token),
|
ContactService: contact.NewContactService(token),
|
||||||
CryptoService: crypto.NewCryptoService(token),
|
CryptoService: crypto.NewCryptoService(token),
|
||||||
CurrencyService: currency.NewCurrencyService(token),
|
CurrencyService: currency.NewCurrencyService(token),
|
||||||
@ -128,6 +130,7 @@ type Client struct {
|
|||||||
AppService *app.AppService
|
AppService *app.AppService
|
||||||
AvatarService *avatar.AvatarService
|
AvatarService *avatar.AvatarService
|
||||||
CacheService *cache.CacheService
|
CacheService *cache.CacheService
|
||||||
|
CarbonService *carbon.CarbonService
|
||||||
ContactService *contact.ContactService
|
ContactService *contact.ContactService
|
||||||
CryptoService *crypto.CryptoService
|
CryptoService *crypto.CryptoService
|
||||||
CurrencyService *currency.CurrencyService
|
CurrencyService *currency.CurrencyService
|
||||||
|
24
services/update.sh
Executable file
24
services/update.sh
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
DIR=/tmp/services
|
||||||
|
CDIR=`pwd`
|
||||||
|
REPO=https://github.com/m3o/m3o-go
|
||||||
|
|
||||||
|
git clone $REPO $DIR
|
||||||
|
cd $DIR
|
||||||
|
|
||||||
|
# move/delete
|
||||||
|
rm -rf .git .github go.mod go.sum README.md CNAME Makefile TODO.md LICENSE client cmd examples
|
||||||
|
mv m3o.go services.go
|
||||||
|
|
||||||
|
# rewrite
|
||||||
|
grep -r "go.m3o.com" | cut -f 1 -d : | xargs sed -i 's@go.m3o.com/client@go-micro.dev/v4/api/client@g'
|
||||||
|
sed -i 's@go.m3o.com@go-micro.dev/v4/services@g' services.go
|
||||||
|
sed -i 's@package m3o@package services@g' services.go
|
||||||
|
|
||||||
|
# sync
|
||||||
|
cd $CDIR
|
||||||
|
rsync -avz $DIR/ .
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
rm -rf $DIR
|
Loading…
Reference in New Issue
Block a user