Skip to content

Commit 4ae2528

Browse files
authored
add m3o services (#2301)
* add m3o services * update readme
1 parent 043a82b commit 4ae2528

File tree

43 files changed

+3856
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3856
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require (
1818
github.com/google/uuid v1.2.0
1919
github.com/gorilla/handlers v1.5.1
2020
github.com/imdario/mergo v0.3.12
21+
github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3
2122
github.com/miekg/dns v1.1.43
2223
github.com/nxadm/tail v1.4.8
2324
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV
7070
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
7171
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
7272
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
73+
github.com/asim/go-micro v1.18.0 h1:k/qyLA5R175Vr1Owf90Ms1+J/zhBf/aa8aiHGhk0x5s=
7374
github.com/aws/aws-sdk-go v1.37.27/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
7475
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
7576
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
@@ -255,6 +256,8 @@ github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv
255256
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
256257
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
257258
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
259+
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
260+
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
258261
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
259262
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
260263
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
@@ -335,6 +338,9 @@ github.com/liquidweb/go-lwApi v0.0.0-20190605172801-52a4864d2738/go.mod h1:0sYF9
335338
github.com/liquidweb/go-lwApi v0.0.5/go.mod h1:0sYF9rMXb0vlG+4SzdiGMXHheCZxjguMq+Zb4S2BfBs=
336339
github.com/liquidweb/liquidweb-cli v0.6.9/go.mod h1:cE1uvQ+x24NGUL75D0QagOFCG8Wdvmwu8aL9TLmA/eQ=
337340
github.com/liquidweb/liquidweb-go v1.6.3/go.mod h1:SuXXp+thr28LnjEw18AYtWwIbWMHSUiajPQs8T9c/Rc=
341+
github.com/m3o/m3o-go v0.0.0-20210917103041-f2f62ad942f7 h1:X2fldKCj7jq4flyxxeBJh7TLZIyKXaU7V4o5zUpLmxg=
342+
github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3 h1:RVt7rqWl4al36BH9OY9k7IXnnooOP0Feanu1bed6X2s=
343+
github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3/go.mod h1:vmeaYrKYpgVNhny/l7iH8mXS88S7ijUiYni3gZUrCq0=
338344
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
339345
github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
340346
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=

services/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import (
7878
"fmt"
7979
"os"
8080

81-
"github.com/micro/services/clients/go/currency"
81+
"github.com/asim/go-micro/v3/services/currency"
8282
)
8383

8484
var (

services/address/address.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package address
2+
3+
import (
4+
"github.com/m3o/m3o-go/client"
5+
)
6+
7+
func NewAddressService(token string) *AddressService {
8+
return &AddressService{
9+
client: client.NewClient(&client.Options{
10+
Token: token,
11+
}),
12+
}
13+
}
14+
15+
type AddressService struct {
16+
client *client.Client
17+
}
18+
19+
// Lookup a list of UK addresses by postcode
20+
func (t *AddressService) LookupPostcode(request *LookupPostcodeRequest) (*LookupPostcodeResponse, error) {
21+
rsp := &LookupPostcodeResponse{}
22+
return rsp, t.client.Call("address", "LookupPostcode", request, rsp)
23+
}
24+
25+
type LookupPostcodeRequest struct {
26+
// UK postcode e.g SW1A 2AA
27+
Postcode string `json:"postcode"`
28+
}
29+
30+
type LookupPostcodeResponse struct {
31+
Addresses []Record `json:"addresses"`
32+
}
33+
34+
type Record struct {
35+
// building name
36+
BuildingName string `json:"buildingName"`
37+
// the county
38+
County string `json:"county"`
39+
// line one of address
40+
LineOne string `json:"lineOne"`
41+
// line two of address
42+
LineTwo string `json:"lineTwo"`
43+
// dependent locality
44+
Locality string `json:"locality"`
45+
// organisation if present
46+
Organisation string `json:"organisation"`
47+
// the postcode
48+
Postcode string `json:"postcode"`
49+
// the premise
50+
Premise string `json:"premise"`
51+
// street name
52+
Street string `json:"street"`
53+
// the complete address
54+
Summary string `json:"summary"`
55+
// post town
56+
Town string `json:"town"`
57+
}

services/answer/answer.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package answer
2+
3+
import (
4+
"github.com/m3o/m3o-go/client"
5+
)
6+
7+
func NewAnswerService(token string) *AnswerService {
8+
return &AnswerService{
9+
client: client.NewClient(&client.Options{
10+
Token: token,
11+
}),
12+
}
13+
}
14+
15+
type AnswerService struct {
16+
client *client.Client
17+
}
18+
19+
// Ask a question and receive an instant answer
20+
func (t *AnswerService) Question(request *QuestionRequest) (*QuestionResponse, error) {
21+
rsp := &QuestionResponse{}
22+
return rsp, t.client.Call("answer", "Question", request, rsp)
23+
}
24+
25+
type QuestionRequest struct {
26+
// the question to answer
27+
Query string `json:"query"`
28+
}
29+
30+
type QuestionResponse struct {
31+
// the answer to your question
32+
Answer string `json:"answer"`
33+
// any related image
34+
Image string `json:"image"`
35+
// a related url
36+
Url string `json:"url"`
37+
}

services/cache/cache.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package cache
2+
3+
import (
4+
"github.com/m3o/m3o-go/client"
5+
)
6+
7+
func NewCacheService(token string) *CacheService {
8+
return &CacheService{
9+
client: client.NewClient(&client.Options{
10+
Token: token,
11+
}),
12+
}
13+
}
14+
15+
type CacheService struct {
16+
client *client.Client
17+
}
18+
19+
// Decrement a value (if it's a number)
20+
func (t *CacheService) Decrement(request *DecrementRequest) (*DecrementResponse, error) {
21+
rsp := &DecrementResponse{}
22+
return rsp, t.client.Call("cache", "Decrement", request, rsp)
23+
}
24+
25+
// Delete a value from the cache
26+
func (t *CacheService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
27+
rsp := &DeleteResponse{}
28+
return rsp, t.client.Call("cache", "Delete", request, rsp)
29+
}
30+
31+
// Get an item from the cache by key
32+
func (t *CacheService) Get(request *GetRequest) (*GetResponse, error) {
33+
rsp := &GetResponse{}
34+
return rsp, t.client.Call("cache", "Get", request, rsp)
35+
}
36+
37+
// Increment a value (if it's a number)
38+
func (t *CacheService) Increment(request *IncrementRequest) (*IncrementResponse, error) {
39+
rsp := &IncrementResponse{}
40+
return rsp, t.client.Call("cache", "Increment", request, rsp)
41+
}
42+
43+
// Set an item in the cache. Overwrites any existing value already set.
44+
func (t *CacheService) Set(request *SetRequest) (*SetResponse, error) {
45+
rsp := &SetResponse{}
46+
return rsp, t.client.Call("cache", "Set", request, rsp)
47+
}
48+
49+
type DecrementRequest struct {
50+
// The key to decrement
51+
Key string `json:"key"`
52+
// The amount to decrement the value by
53+
Value int64 `json:"value,string"`
54+
}
55+
56+
type DecrementResponse struct {
57+
// The key decremented
58+
Key string `json:"key"`
59+
// The new value
60+
Value int64 `json:"value,string"`
61+
}
62+
63+
type DeleteRequest struct {
64+
// The key to delete
65+
Key string `json:"key"`
66+
}
67+
68+
type DeleteResponse struct {
69+
// Returns "ok" if successful
70+
Status string `json:"status"`
71+
}
72+
73+
type GetRequest struct {
74+
// The key to retrieve
75+
Key string `json:"key"`
76+
}
77+
78+
type GetResponse struct {
79+
// The key
80+
Key string `json:"key"`
81+
// Time to live in seconds
82+
Ttl int64 `json:"ttl,string"`
83+
// The value
84+
Value string `json:"value"`
85+
}
86+
87+
type IncrementRequest struct {
88+
// The key to increment
89+
Key string `json:"key"`
90+
// The amount to increment the value by
91+
Value int64 `json:"value,string"`
92+
}
93+
94+
type IncrementResponse struct {
95+
// The key incremented
96+
Key string `json:"key"`
97+
// The new value
98+
Value int64 `json:"value,string"`
99+
}
100+
101+
type SetRequest struct {
102+
// The key to update
103+
Key string `json:"key"`
104+
// Time to live in seconds
105+
Ttl int64 `json:"ttl,string"`
106+
// The value to set
107+
Value string `json:"value"`
108+
}
109+
110+
type SetResponse struct {
111+
// Returns "ok" if successful
112+
Status string `json:"status"`
113+
}

services/crypto/crypto.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package crypto
2+
3+
import (
4+
"github.com/m3o/m3o-go/client"
5+
)
6+
7+
func NewCryptoService(token string) *CryptoService {
8+
return &CryptoService{
9+
client: client.NewClient(&client.Options{
10+
Token: token,
11+
}),
12+
}
13+
}
14+
15+
type CryptoService struct {
16+
client *client.Client
17+
}
18+
19+
// Returns the history for the previous close
20+
func (t *CryptoService) History(request *HistoryRequest) (*HistoryResponse, error) {
21+
rsp := &HistoryResponse{}
22+
return rsp, t.client.Call("crypto", "History", request, rsp)
23+
}
24+
25+
// Get news related to a currency
26+
func (t *CryptoService) News(request *NewsRequest) (*NewsResponse, error) {
27+
rsp := &NewsResponse{}
28+
return rsp, t.client.Call("crypto", "News", request, rsp)
29+
}
30+
31+
// Get the last price for a given crypto ticker
32+
func (t *CryptoService) Price(request *PriceRequest) (*PriceResponse, error) {
33+
rsp := &PriceResponse{}
34+
return rsp, t.client.Call("crypto", "Price", request, rsp)
35+
}
36+
37+
// Get the last quote for a given crypto ticker
38+
func (t *CryptoService) Quote(request *QuoteRequest) (*QuoteResponse, error) {
39+
rsp := &QuoteResponse{}
40+
return rsp, t.client.Call("crypto", "Quote", request, rsp)
41+
}
42+
43+
type Article struct {
44+
// the date published
45+
Date string `json:"date"`
46+
// its description
47+
Description string `json:"description"`
48+
// the source
49+
Source string `json:"source"`
50+
// title of the article
51+
Title string `json:"title"`
52+
// the source url
53+
Url string `json:"url"`
54+
}
55+
56+
type HistoryRequest struct {
57+
// the crypto symbol e.g BTCUSD
58+
Symbol string `json:"symbol"`
59+
}
60+
61+
type HistoryResponse struct {
62+
// the close price
63+
Close float64 `json:"close"`
64+
// the date
65+
Date string `json:"date"`
66+
// the peak price
67+
High float64 `json:"high"`
68+
// the low price
69+
Low float64 `json:"low"`
70+
// the open price
71+
Open float64 `json:"open"`
72+
// the crypto symbol
73+
Symbol string `json:"symbol"`
74+
// the volume
75+
Volume float64 `json:"volume"`
76+
}
77+
78+
type NewsRequest struct {
79+
// cryptocurrency ticker to request news for e.g BTC
80+
Symbol string `json:"symbol"`
81+
}
82+
83+
type NewsResponse struct {
84+
// list of articles
85+
Articles []Article `json:"articles"`
86+
// symbol requested for
87+
Symbol string `json:"symbol"`
88+
}
89+
90+
type PriceRequest struct {
91+
// the crypto symbol e.g BTCUSD
92+
Symbol string `json:"symbol"`
93+
}
94+
95+
type PriceResponse struct {
96+
// the last price
97+
Price float64 `json:"price"`
98+
// the crypto symbol e.g BTCUSD
99+
Symbol string `json:"symbol"`
100+
}
101+
102+
type QuoteRequest struct {
103+
// the crypto symbol e.g BTCUSD
104+
Symbol string `json:"symbol"`
105+
}
106+
107+
type QuoteResponse struct {
108+
// the asking price
109+
AskPrice float64 `json:"askPrice"`
110+
// the ask size
111+
AskSize float64 `json:"askSize"`
112+
// the bidding price
113+
BidPrice float64 `json:"bidPrice"`
114+
// the bid size
115+
BidSize float64 `json:"bidSize"`
116+
// the crypto symbol
117+
Symbol string `json:"symbol"`
118+
// the UTC timestamp of the quote
119+
Timestamp string `json:"timestamp"`
120+
}

0 commit comments

Comments
 (0)