mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-24 07:25:35 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c12e0e2c49 | ||
|
|
0235f16741 |
31
.github/workflows/generate.yml
vendored
31
.github/workflows/generate.yml
vendored
@@ -1,31 +0,0 @@
|
|||||||
name: Test Clients
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- beta
|
|
||||||
- ci
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
generate:
|
|
||||||
name: Test Clients
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Check out repo
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
path: clients
|
|
||||||
#ref: main
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
working-directory: clients
|
|
||||||
env:
|
|
||||||
M3O_API_TOKEN: ${{ secrets.M3O_API_TOKEN }}
|
|
||||||
run: |
|
|
||||||
# stream is temporarily excluded as it hangs forever because test does not close connection
|
|
||||||
# @TODO remove "idempotent: true" from stream example
|
|
||||||
O=$(find . -name ".run" | grep -v stream | xargs -n1 dirname | xargs -n1 go run)
|
|
||||||
echo $O
|
|
||||||
if grep -q Detail "$O"; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
70
README.md
70
README.md
@@ -1,37 +1,6 @@
|
|||||||
# M3O Go Client [](https://godoc.org/github.com/m3o/m3o-go) [](https://goreportcard.com/report/github.com/m3o/m3o-go) [](https://github.com/m3o/m3o-go/blob/master/LICENSE)
|
# M3O Go Client
|
||||||
|
|
||||||
This is the Go client to access APIs on the M3O Platform
|
By default the client connects to api.m3o.com/client
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Call a service using the generated client. Populate the `M3O_API_TOKEN` environment variable.
|
|
||||||
|
|
||||||
Import the package and initialise the service with your API token.
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/helloworld"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Call returns a personalised "Hello $name" response
|
|
||||||
func main() {
|
|
||||||
helloworldService := helloworld.NewHelloworldService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := helloworldService.Call(&helloworld.CallRequest{
|
|
||||||
Name: "John",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Generic Client
|
|
||||||
|
|
||||||
The generic client enables you to call any endpoint by name with freeform request/response types.
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -40,7 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"go.m3o.com/client"
|
"github.com/m3o/m3o-go/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
@@ -64,29 +33,39 @@ func main() {
|
|||||||
req := &Request{
|
req := &Request{
|
||||||
Name: "John",
|
Name: "John",
|
||||||
}
|
}
|
||||||
|
|
||||||
var rsp Response
|
var rsp Response
|
||||||
|
|
||||||
if err := c.Call("helloworld", "call", req, &rsp); err != nil {
|
if err := c.Call("greeter", "Say.Hello", req, &rsp); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(rsp)
|
fmt.Println(rsp)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to access your local micro:
|
||||||
|
|
||||||
|
```go
|
||||||
|
c := client.NewClient(client.Options{Local: true})
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also set the api address explicitly:
|
||||||
|
|
||||||
|
```go
|
||||||
|
c := client.NewClient(client.Options{Address: "https://api.yourdomain.com/client"})
|
||||||
|
```
|
||||||
|
|
||||||
## Streaming
|
## Streaming
|
||||||
|
|
||||||
The client supports streaming but is not yet code generated. Use the following for streaming endpoints.
|
The client supports streaming
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"go.m3o.com/client"
|
"github.com/m3o/m3o-go/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
@@ -97,17 +76,10 @@ type Response struct {
|
|||||||
Count string `json:"count"`
|
Count string `json:"count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
token, _ = os.Getenv("TOKEN")
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := client.NewClient(nil)
|
c := client.NewClient(&client.Options{Local: true})
|
||||||
|
|
||||||
// set your api token
|
stream, err := c.Stream("example", "Streamer.ServerStream", Request{Count: "10"})
|
||||||
c.SetToken(token)
|
|
||||||
|
|
||||||
stream, err := c.Stream("streams", "subscribe", Request{Count: "10"})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
package address
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Address interface {
|
|
||||||
LookupPostcode(*LookupPostcodeRequest) (*LookupPostcodeResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAddressService(token string) *AddressService {
|
|
||||||
return &AddressService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddressService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lookup a list of UK addresses by postcode
|
|
||||||
func (t *AddressService) LookupPostcode(request *LookupPostcodeRequest) (*LookupPostcodeResponse, error) {
|
|
||||||
|
|
||||||
rsp := &LookupPostcodeResponse{}
|
|
||||||
return rsp, t.client.Call("address", "LookupPostcode", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type LookupPostcodeRequest struct {
|
|
||||||
// UK postcode e.g SW1A 2AA
|
|
||||||
Postcode string `json:"postcode"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type LookupPostcodeResponse struct {
|
|
||||||
Addresses []Record `json:"addresses"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Record struct {
|
|
||||||
// building name
|
|
||||||
BuildingName string `json:"building_name"`
|
|
||||||
// the county
|
|
||||||
County string `json:"county"`
|
|
||||||
// line one of address
|
|
||||||
LineOne string `json:"line_one"`
|
|
||||||
// line two of address
|
|
||||||
LineTwo string `json:"line_two"`
|
|
||||||
// dependent locality
|
|
||||||
Locality string `json:"locality"`
|
|
||||||
// organisation if present
|
|
||||||
Organisation string `json:"organisation"`
|
|
||||||
// the postcode
|
|
||||||
Postcode string `json:"postcode"`
|
|
||||||
// the premise
|
|
||||||
Premise string `json:"premise"`
|
|
||||||
// street name
|
|
||||||
Street string `json:"street"`
|
|
||||||
// the complete address
|
|
||||||
Summary string `json:"summary"`
|
|
||||||
// post town
|
|
||||||
Town string `json:"town"`
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package answer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Answer interface {
|
|
||||||
Question(*QuestionRequest) (*QuestionResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAnswerService(token string) *AnswerService {
|
|
||||||
return &AnswerService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type AnswerService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ask a question and receive an instant answer
|
|
||||||
func (t *AnswerService) Question(request *QuestionRequest) (*QuestionResponse, error) {
|
|
||||||
|
|
||||||
rsp := &QuestionResponse{}
|
|
||||||
return rsp, t.client.Call("answer", "Question", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type QuestionRequest struct {
|
|
||||||
// the question to answer
|
|
||||||
Query string `json:"query"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type QuestionResponse struct {
|
|
||||||
// the answer to your question
|
|
||||||
Answer string `json:"answer"`
|
|
||||||
// any related image
|
|
||||||
Image string `json:"image"`
|
|
||||||
// a related url
|
|
||||||
Url string `json:"url"`
|
|
||||||
}
|
|
||||||
213
app/app.go
213
app/app.go
@@ -1,213 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type App interface {
|
|
||||||
Delete(*DeleteRequest) (*DeleteResponse, error)
|
|
||||||
List(*ListRequest) (*ListResponse, error)
|
|
||||||
Regions(*RegionsRequest) (*RegionsResponse, error)
|
|
||||||
Reserve(*ReserveRequest) (*ReserveResponse, error)
|
|
||||||
Resolve(*ResolveRequest) (*ResolveResponse, error)
|
|
||||||
Run(*RunRequest) (*RunResponse, error)
|
|
||||||
Status(*StatusRequest) (*StatusResponse, error)
|
|
||||||
Update(*UpdateRequest) (*UpdateResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAppService(token string) *AppService {
|
|
||||||
return &AppService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete an app
|
|
||||||
func (t *AppService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
|
||||||
|
|
||||||
rsp := &DeleteResponse{}
|
|
||||||
return rsp, t.client.Call("app", "Delete", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// List all the apps
|
|
||||||
func (t *AppService) List(request *ListRequest) (*ListResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ListResponse{}
|
|
||||||
return rsp, t.client.Call("app", "List", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the support regions
|
|
||||||
func (t *AppService) Regions(request *RegionsRequest) (*RegionsResponse, error) {
|
|
||||||
|
|
||||||
rsp := &RegionsResponse{}
|
|
||||||
return rsp, t.client.Call("app", "Regions", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reserve apps beyond the free quota. Call Run after.
|
|
||||||
func (t *AppService) Reserve(request *ReserveRequest) (*ReserveResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ReserveResponse{}
|
|
||||||
return rsp, t.client.Call("app", "Reserve", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve an app by id to its raw backend endpoint
|
|
||||||
func (t *AppService) Resolve(request *ResolveRequest) (*ResolveResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ResolveResponse{}
|
|
||||||
return rsp, t.client.Call("app", "Resolve", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run an app from source
|
|
||||||
func (t *AppService) Run(request *RunRequest) (*RunResponse, error) {
|
|
||||||
|
|
||||||
rsp := &RunResponse{}
|
|
||||||
return rsp, t.client.Call("app", "Run", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the status of an app
|
|
||||||
func (t *AppService) Status(request *StatusRequest) (*StatusResponse, error) {
|
|
||||||
|
|
||||||
rsp := &StatusResponse{}
|
|
||||||
return rsp, t.client.Call("app", "Status", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the app. The latest source code will be downloaded, built and deployed.
|
|
||||||
func (t *AppService) Update(request *UpdateRequest) (*UpdateResponse, error) {
|
|
||||||
|
|
||||||
rsp := &UpdateResponse{}
|
|
||||||
return rsp, t.client.Call("app", "Update", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteRequest struct {
|
|
||||||
// name of the app
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteResponse struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListRequest struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListResponse struct {
|
|
||||||
// all the apps
|
|
||||||
Services []Service `json:"services"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RegionsRequest struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type RegionsResponse struct {
|
|
||||||
Regions []string `json:"regions"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Reservation struct {
|
|
||||||
// time of reservation
|
|
||||||
Created string `json:"created"`
|
|
||||||
// time reservation expires
|
|
||||||
Expires string `json:"expires"`
|
|
||||||
// name of the app
|
|
||||||
Name string `json:"name"`
|
|
||||||
// owner id
|
|
||||||
Owner string `json:"owner"`
|
|
||||||
// associated token
|
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReserveRequest struct {
|
|
||||||
// name of your app e.g helloworld
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReserveResponse struct {
|
|
||||||
// The app reservation
|
|
||||||
Reservation *Reservation `json:"reservation"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResolveRequest struct {
|
|
||||||
// the service id
|
|
||||||
Id string `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResolveResponse struct {
|
|
||||||
// the end provider url
|
|
||||||
Url string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RunRequest struct {
|
|
||||||
// branch. defaults to master
|
|
||||||
Branch string `json:"branch"`
|
|
||||||
// associated env vars to pass in
|
|
||||||
EnvVars map[string]string `json:"env_vars"`
|
|
||||||
// name of the app
|
|
||||||
Name string `json:"name"`
|
|
||||||
// port to run on
|
|
||||||
Port int32 `json:"port"`
|
|
||||||
// region to run in
|
|
||||||
Region string `json:"region"`
|
|
||||||
// source repository
|
|
||||||
Repo string `json:"repo"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RunResponse struct {
|
|
||||||
// The running service
|
|
||||||
Service *Service `json:"service"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Service struct {
|
|
||||||
// branch of code
|
|
||||||
Branch string `json:"branch"`
|
|
||||||
// time of creation
|
|
||||||
Created string `json:"created"`
|
|
||||||
// custom domains
|
|
||||||
CustomDomains string `json:"custom_domains"`
|
|
||||||
// associated env vars
|
|
||||||
EnvVars map[string]string `json:"env_vars"`
|
|
||||||
// unique id
|
|
||||||
Id string `json:"id"`
|
|
||||||
// name of the app
|
|
||||||
Name string `json:"name"`
|
|
||||||
// port running on
|
|
||||||
Port int32 `json:"port"`
|
|
||||||
// region running in
|
|
||||||
Region string `json:"region"`
|
|
||||||
// source repository
|
|
||||||
Repo string `json:"repo"`
|
|
||||||
// status of the app
|
|
||||||
Status string `json:"status"`
|
|
||||||
// last updated
|
|
||||||
Updated string `json:"updated"`
|
|
||||||
// app url
|
|
||||||
Url string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type StatusRequest struct {
|
|
||||||
// name of the app
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type StatusResponse struct {
|
|
||||||
// running service info
|
|
||||||
Service *Service `json:"service"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateRequest struct {
|
|
||||||
// name of the app
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateResponse struct {
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package avatar
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Avatar interface {
|
|
||||||
Generate(*GenerateRequest) (*GenerateResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAvatarService(token string) *AvatarService {
|
|
||||||
return &AvatarService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type AvatarService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
func (t *AvatarService) Generate(request *GenerateRequest) (*GenerateResponse, error) {
|
|
||||||
|
|
||||||
rsp := &GenerateResponse{}
|
|
||||||
return rsp, t.client.Call("avatar", "Generate", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type GenerateRequest struct {
|
|
||||||
// encode format of avatar image, `png` or `jpeg`, default is `jpeg`
|
|
||||||
Format string `json:"format"`
|
|
||||||
// avatar's gender, `male` or `female`, default is `male`
|
|
||||||
Gender string `json:"gender"`
|
|
||||||
// if upload to m3o CDN, default is `false`
|
|
||||||
// if update = true, then it'll return the CDN url
|
|
||||||
Upload bool `json:"upload"`
|
|
||||||
// avatar's username, unique username will generates the unique avatar;
|
|
||||||
// if username == "", will generate a random avatar in every request
|
|
||||||
// if upload == true, username will be used as CDN filename rather than a random uuid string
|
|
||||||
Username string `json:"username"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GenerateResponse struct {
|
|
||||||
// base64encode string of the avatar image
|
|
||||||
Base64 string `json:"base64"`
|
|
||||||
// Micro's CDN url of the avatar image
|
|
||||||
Url string `json:"url"`
|
|
||||||
}
|
|
||||||
147
cache/cache.go
vendored
147
cache/cache.go
vendored
@@ -1,147 +0,0 @@
|
|||||||
package cache
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Cache interface {
|
|
||||||
Decrement(*DecrementRequest) (*DecrementResponse, error)
|
|
||||||
Delete(*DeleteRequest) (*DeleteResponse, error)
|
|
||||||
Get(*GetRequest) (*GetResponse, error)
|
|
||||||
Increment(*IncrementRequest) (*IncrementResponse, error)
|
|
||||||
ListKeys(*ListKeysRequest) (*ListKeysResponse, error)
|
|
||||||
Set(*SetRequest) (*SetResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCacheService(token string) *CacheService {
|
|
||||||
return &CacheService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type CacheService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decrement a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
func (t *CacheService) Decrement(request *DecrementRequest) (*DecrementResponse, error) {
|
|
||||||
|
|
||||||
rsp := &DecrementResponse{}
|
|
||||||
return rsp, t.client.Call("cache", "Decrement", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete a value from the cache. If key not found a success response is returned.
|
|
||||||
func (t *CacheService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
|
||||||
|
|
||||||
rsp := &DeleteResponse{}
|
|
||||||
return rsp, t.client.Call("cache", "Delete", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get an item from the cache by key. If key is not found, an empty response is returned.
|
|
||||||
func (t *CacheService) Get(request *GetRequest) (*GetResponse, error) {
|
|
||||||
|
|
||||||
rsp := &GetResponse{}
|
|
||||||
return rsp, t.client.Call("cache", "Get", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
func (t *CacheService) Increment(request *IncrementRequest) (*IncrementResponse, error) {
|
|
||||||
|
|
||||||
rsp := &IncrementResponse{}
|
|
||||||
return rsp, t.client.Call("cache", "Increment", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
func (t *CacheService) Set(request *SetRequest) (*SetResponse, error) {
|
|
||||||
|
|
||||||
rsp := &SetResponse{}
|
|
||||||
return rsp, t.client.Call("cache", "Set", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type DecrementRequest struct {
|
|
||||||
// The key to decrement
|
|
||||||
Key string `json:"key"`
|
|
||||||
// The amount to decrement the value by
|
|
||||||
Value int64 `json:"value,string"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DecrementResponse struct {
|
|
||||||
// The key decremented
|
|
||||||
Key string `json:"key"`
|
|
||||||
// The new value
|
|
||||||
Value int64 `json:"value,string"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteRequest struct {
|
|
||||||
// The key to delete
|
|
||||||
Key string `json:"key"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteResponse struct {
|
|
||||||
// Returns "ok" if successful
|
|
||||||
Status string `json:"status"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetRequest struct {
|
|
||||||
// The key to retrieve
|
|
||||||
Key string `json:"key"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetResponse struct {
|
|
||||||
// The key
|
|
||||||
Key string `json:"key"`
|
|
||||||
// Time to live in seconds
|
|
||||||
Ttl int64 `json:"ttl,string"`
|
|
||||||
// The value
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IncrementRequest struct {
|
|
||||||
// The key to increment
|
|
||||||
Key string `json:"key"`
|
|
||||||
// The amount to increment the value by
|
|
||||||
Value int64 `json:"value,string"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IncrementResponse struct {
|
|
||||||
// The key incremented
|
|
||||||
Key string `json:"key"`
|
|
||||||
// The new value
|
|
||||||
Value int64 `json:"value,string"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListKeysRequest struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListKeysResponse struct {
|
|
||||||
Keys []string `json:"keys"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SetRequest struct {
|
|
||||||
// The key to update
|
|
||||||
Key string `json:"key"`
|
|
||||||
// Time to live in seconds
|
|
||||||
Ttl int64 `json:"ttl,string"`
|
|
||||||
// The value to set
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SetResponse struct {
|
|
||||||
// Returns "ok" if successful
|
|
||||||
Status string `json:"status"`
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package carbon
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/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"`
|
|
||||||
}
|
|
||||||
@@ -8,16 +8,15 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// local address for api
|
// local address for api
|
||||||
localAddress = "http://localhost:8080"
|
localAddress = "http://localhost:8080/"
|
||||||
// public address for api
|
// public address for api
|
||||||
liveAddress = "https://api.m3o.com"
|
liveAddress = "https://api.m3o.com/"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options of the Client
|
// Options of the Client
|
||||||
@@ -30,8 +29,6 @@ type Options struct {
|
|||||||
Address string
|
Address string
|
||||||
// Helper flag to help users connect to the default local address
|
// Helper flag to help users connect to the default local address
|
||||||
Local bool
|
Local bool
|
||||||
// set a timeout
|
|
||||||
Timeout time.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request is the request of the generic `api-client` call
|
// Request is the request of the generic `api-client` call
|
||||||
@@ -72,25 +69,13 @@ func NewClient(options *Options) *Client {
|
|||||||
ret.options = Options{
|
ret.options = Options{
|
||||||
Address: liveAddress,
|
Address: liveAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
// no options provided
|
|
||||||
if options == nil {
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.Token != "" {
|
if options.Token != "" {
|
||||||
ret.options.Token = options.Token
|
ret.options.Token = options.Token
|
||||||
}
|
}
|
||||||
|
if options != nil && options.Local {
|
||||||
if options.Local {
|
|
||||||
ret.options.Address = localAddress
|
ret.options.Address = localAddress
|
||||||
ret.options.Local = true
|
ret.options.Local = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Timeout > 0 {
|
|
||||||
ret.options.Timeout = options.Timeout
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,11 +84,6 @@ func (client *Client) SetToken(t string) {
|
|||||||
client.options.Token = t
|
client.options.Token = t
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTimeout sets the http client's timeout
|
|
||||||
func (client *Client) SetTimeout(d time.Duration) {
|
|
||||||
client.options.Timeout = d
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call enables you to access any endpoint of any service on Micro
|
// Call enables you to access any endpoint of any service on Micro
|
||||||
func (client *Client) Call(service, endpoint string, request, response interface{}) error {
|
func (client *Client) Call(service, endpoint string, request, response interface{}) error {
|
||||||
// example curl: curl -XPOST -d '{"service": "go.micro.srv.greeter", "endpoint": "Say.Hello"}'
|
// example curl: curl -XPOST -d '{"service": "go.micro.srv.greeter", "endpoint": "Say.Hello"}'
|
||||||
@@ -112,8 +92,7 @@ func (client *Client) Call(service, endpoint string, request, response interface
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// TODO: make optional
|
||||||
// set the url to go through the v1 api
|
|
||||||
uri.Path = "/v1/" + service + "/" + endpoint
|
uri.Path = "/v1/" + service + "/" + endpoint
|
||||||
|
|
||||||
b, err := marshalRequest(service, endpoint, request)
|
b, err := marshalRequest(service, endpoint, request)
|
||||||
@@ -133,11 +112,7 @@ func (client *Client) Call(service, endpoint string, request, response interface
|
|||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
// if user didn't specify Timeout the default is 0 i.e no timeout
|
httpClient := &http.Client{}
|
||||||
httpClient := &http.Client{
|
|
||||||
Timeout: client.options.Timeout,
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -165,9 +140,8 @@ func (client *Client) Stream(service, endpoint string, request interface{}) (*St
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// TODO: make optional
|
||||||
// set the url to go through the v1 api
|
uri.Path = "/client/stream"
|
||||||
uri.Path = "/v1/" + service + "/" + endpoint
|
|
||||||
|
|
||||||
// replace http with websocket
|
// replace http with websocket
|
||||||
uri.Scheme = strings.Replace(uri.Scheme, "http", "ws", 1)
|
uri.Scheme = strings.Replace(uri.Scheme, "http", "ws", 1)
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestBasicCall(t *testing.T) {
|
func TestBasicCall(t *testing.T) {
|
||||||
if v := os.Getenv("IN_TRAVIS"); v == "yes" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
response := map[string]interface{}{}
|
response := map[string]interface{}{}
|
||||||
if err := NewClient(&Options{
|
if err := NewClient(&Options{
|
||||||
Token: os.Getenv("TOKEN"),
|
Token: os.Getenv("TOKEN"),
|
||||||
|
|||||||
5
client/go.mod
Normal file
5
client/go.mod
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module github.com/micro/clients/go/client
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require github.com/gorilla/websocket v1.4.1
|
||||||
2
client/go.sum
Normal file
2
client/go.sum
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
|
||||||
|
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
@@ -1,201 +0,0 @@
|
|||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright {yyyy} {name of copyright owner}
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
# M3O Go Vanity URL
|
|
||||||
|
|
||||||
M3O Go Vanity URL is a simple Go server that sets the custom url `go.m3o.com`
|
|
||||||
|
|
||||||
## Quickstart
|
|
||||||
|
|
||||||
Install and run the binary:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ go get -u github.com/m3o-go/cmd/m3o-go-url
|
|
||||||
$ # update vanity.yaml
|
|
||||||
$ m3o-go-url
|
|
||||||
$ # open http://localhost:8080
|
|
||||||
```
|
|
||||||
|
|
||||||
### Google App Engine
|
|
||||||
|
|
||||||
Install [gcloud](https://cloud.google.com/sdk/downloads) and install Go App Engine component:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ gcloud components install app-engine-go
|
|
||||||
```
|
|
||||||
|
|
||||||
Setup a [custom domain](https://cloud.google.com/appengine/docs/standard/python/using-custom-domains-and-ssl) for your app.
|
|
||||||
|
|
||||||
Get the application:
|
|
||||||
```
|
|
||||||
git clone https://github.com/GoogleCloudPlatform/govanityurls
|
|
||||||
cd govanityurls
|
|
||||||
```
|
|
||||||
|
|
||||||
Edit `vanity.yaml` to add any number of git repos. E.g., `customdomain.com/portmidi` will
|
|
||||||
serve the [https://github.com/rakyll/portmidi](https://github.com/rakyll/portmidi) repo.
|
|
||||||
|
|
||||||
```
|
|
||||||
paths:
|
|
||||||
/portmidi:
|
|
||||||
repo: https://github.com/rakyll/portmidi
|
|
||||||
```
|
|
||||||
|
|
||||||
You can add as many rules as you wish.
|
|
||||||
|
|
||||||
Deploy the app:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ gcloud app deploy
|
|
||||||
```
|
|
||||||
|
|
||||||
That's it! You can use `go get` to get the package from your custom domain.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ go get customdomain.com/portmidi
|
|
||||||
```
|
|
||||||
|
|
||||||
### Running in other environments
|
|
||||||
|
|
||||||
You can also deploy this as an App Engine Flexible app by changing the
|
|
||||||
`app.yaml` file:
|
|
||||||
|
|
||||||
```
|
|
||||||
runtime: go
|
|
||||||
env: flex
|
|
||||||
```
|
|
||||||
|
|
||||||
This project is a normal Go HTTP server, so you can also incorporate the
|
|
||||||
handler into larger Go servers.
|
|
||||||
|
|
||||||
## Configuration File
|
|
||||||
|
|
||||||
```
|
|
||||||
host: example.com
|
|
||||||
cache_max_age: 3600
|
|
||||||
paths:
|
|
||||||
/foo:
|
|
||||||
repo: https://github.com/example/foo
|
|
||||||
display: "https://github.com/example/foo https://github.com/example/foo/tree/master{/dir} https://github.com/example/foo/blob/master{/dir}/{file}#L{line}"
|
|
||||||
vcs: git
|
|
||||||
```
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">Key</th>
|
|
||||||
<th scope="col">Required</th>
|
|
||||||
<th scope="col">Description</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row"><code>cache_max_age</code></th>
|
|
||||||
<td>optional</td>
|
|
||||||
<td>The amount of time to cache package pages in seconds. Controls the <code>max-age</code> directive sent in the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control"><code>Cache-Control</code></a> HTTP header.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row"><code>host</code></th>
|
|
||||||
<td>optional</td>
|
|
||||||
<td>Host name to use in meta tags. If omitted, uses the App Engine default version host or the Host header on non-App Engine Standard environments. You can use this option to fix the host when using this service behind a reverse proxy or a <a href="https://cloud.google.com/appengine/docs/standard/go/how-requests-are-routed#routing_with_a_dispatch_file">custom dispatch file</a>.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row"><code>paths</code></th>
|
|
||||||
<td>required</td>
|
|
||||||
<td>Map of paths to path configurations. Each key is a path that will point to the root of a repository hosted elsewhere. The fields are documented in the Path Configuration section below.</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
### Path Configuration
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">Key</th>
|
|
||||||
<th scope="col">Required</th>
|
|
||||||
<th scope="col">Description</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row"><code>display</code></th>
|
|
||||||
<td>optional</td>
|
|
||||||
<td>The last three fields of the <a href="https://github.com/golang/gddo/wiki/Source-Code-Links"><code>go-source</code> meta tag</a>. If omitted, it is inferred from the code hosting service if possible.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row"><code>repo</code></th>
|
|
||||||
<td>required</td>
|
|
||||||
<td>Root URL of the repository as it would appear in <a href="https://golang.org/cmd/go/#hdr-Remote_import_paths"><code>go-import</code> meta tag</a>.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row"><code>vcs</code></th>
|
|
||||||
<td>required if ambiguous</td>
|
|
||||||
<td>If the version control system cannot be inferred (e.g. for Bitbucket or a custom domain), then this specifies the version control system as it would appear in <a href="https://golang.org/cmd/go/#hdr-Remote_import_paths"><code>go-import</code> meta tag</a>. This can be one of <code>git</code>, <code>hg</code>, <code>svn</code>, or <code>bzr</code>.</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
module github.com/m3o/m3o-go/cmd/m3o-go-url
|
|
||||||
|
|
||||||
go 1.13
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/golang/protobuf v1.3.3 // indirect
|
|
||||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect
|
|
||||||
google.golang.org/appengine v1.6.5
|
|
||||||
gopkg.in/yaml.v2 v2.2.8
|
|
||||||
)
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
|
||||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
@@ -1,225 +0,0 @@
|
|||||||
// Copyright 2017 Google Inc. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// govanityurls serves Go vanity URLs.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"net/http"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type handler struct {
|
|
||||||
host string
|
|
||||||
cacheControl string
|
|
||||||
paths pathConfigSet
|
|
||||||
}
|
|
||||||
|
|
||||||
type pathConfig struct {
|
|
||||||
path string
|
|
||||||
repo string
|
|
||||||
display string
|
|
||||||
vcs string
|
|
||||||
}
|
|
||||||
|
|
||||||
func newHandler(config []byte) (*handler, error) {
|
|
||||||
var parsed struct {
|
|
||||||
Host string `yaml:"host,omitempty"`
|
|
||||||
CacheAge *int64 `yaml:"cache_max_age,omitempty"`
|
|
||||||
Paths map[string]struct {
|
|
||||||
Repo string `yaml:"repo,omitempty"`
|
|
||||||
Display string `yaml:"display,omitempty"`
|
|
||||||
VCS string `yaml:"vcs,omitempty"`
|
|
||||||
} `yaml:"paths,omitempty"`
|
|
||||||
}
|
|
||||||
if err := yaml.Unmarshal(config, &parsed); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
h := &handler{host: parsed.Host}
|
|
||||||
cacheAge := int64(86400) // 24 hours (in seconds)
|
|
||||||
if parsed.CacheAge != nil {
|
|
||||||
cacheAge = *parsed.CacheAge
|
|
||||||
if cacheAge < 0 {
|
|
||||||
return nil, errors.New("cache_max_age is negative")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
h.cacheControl = fmt.Sprintf("public, max-age=%d", cacheAge)
|
|
||||||
for path, e := range parsed.Paths {
|
|
||||||
pc := pathConfig{
|
|
||||||
path: strings.TrimSuffix(path, "/"),
|
|
||||||
repo: e.Repo,
|
|
||||||
display: e.Display,
|
|
||||||
vcs: e.VCS,
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case e.Display != "":
|
|
||||||
// Already filled in.
|
|
||||||
case strings.HasPrefix(e.Repo, "https://github.com/"):
|
|
||||||
pc.display = fmt.Sprintf("%v %v/tree/master{/dir} %v/blob/master{/dir}/{file}#L{line}", e.Repo, e.Repo, e.Repo)
|
|
||||||
case strings.HasPrefix(e.Repo, "https://bitbucket.org"):
|
|
||||||
pc.display = fmt.Sprintf("%v %v/src/default{/dir} %v/src/default{/dir}/{file}#{file}-{line}", e.Repo, e.Repo, e.Repo)
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case e.VCS != "":
|
|
||||||
// Already filled in.
|
|
||||||
if e.VCS != "bzr" && e.VCS != "git" && e.VCS != "hg" && e.VCS != "svn" {
|
|
||||||
return nil, fmt.Errorf("configuration for %v: unknown VCS %s", path, e.VCS)
|
|
||||||
}
|
|
||||||
case strings.HasPrefix(e.Repo, "https://github.com/"):
|
|
||||||
pc.vcs = "git"
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("configuration for %v: cannot infer VCS from %s", path, e.Repo)
|
|
||||||
}
|
|
||||||
h.paths = append(h.paths, pc)
|
|
||||||
}
|
|
||||||
sort.Sort(h.paths)
|
|
||||||
return h, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
current := r.URL.Path
|
|
||||||
pc, subpath := h.paths.find(current)
|
|
||||||
if pc == nil && current == "/" {
|
|
||||||
h.serveIndex(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if pc == nil {
|
|
||||||
http.NotFound(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Cache-Control", h.cacheControl)
|
|
||||||
if err := vanityTmpl.Execute(w, struct {
|
|
||||||
Import string
|
|
||||||
Subpath string
|
|
||||||
Repo string
|
|
||||||
Display string
|
|
||||||
VCS string
|
|
||||||
}{
|
|
||||||
Import: h.Host(r) + pc.path,
|
|
||||||
Subpath: subpath,
|
|
||||||
Repo: pc.repo,
|
|
||||||
Display: pc.display,
|
|
||||||
VCS: pc.vcs,
|
|
||||||
}); err != nil {
|
|
||||||
http.Error(w, "cannot render the page", http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *handler) serveIndex(w http.ResponseWriter, r *http.Request) {
|
|
||||||
host := h.Host(r)
|
|
||||||
handlers := make([]string, len(h.paths))
|
|
||||||
for i, h := range h.paths {
|
|
||||||
handlers[i] = host + h.path
|
|
||||||
}
|
|
||||||
if err := indexTmpl.Execute(w, struct {
|
|
||||||
Host string
|
|
||||||
Handlers []string
|
|
||||||
}{
|
|
||||||
Host: host,
|
|
||||||
Handlers: handlers,
|
|
||||||
}); err != nil {
|
|
||||||
http.Error(w, "cannot render the page", http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *handler) Host(r *http.Request) string {
|
|
||||||
host := h.host
|
|
||||||
if host == "" {
|
|
||||||
host = defaultHost(r)
|
|
||||||
}
|
|
||||||
return host
|
|
||||||
}
|
|
||||||
|
|
||||||
var indexTmpl = template.Must(template.New("index").Parse(`<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<h1>{{.Host}}</h1>
|
|
||||||
<ul>
|
|
||||||
{{range .Handlers}}<li><a href="https://pkg.go.dev/{{.}}">{{.}}</a></li>{{end}}
|
|
||||||
</ul>
|
|
||||||
</html>
|
|
||||||
`))
|
|
||||||
|
|
||||||
var vanityTmpl = template.Must(template.New("vanity").Parse(`<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
|
||||||
<meta name="go-import" content="{{.Import}} {{.VCS}} {{.Repo}}">
|
|
||||||
<meta name="go-source" content="{{.Import}} {{.Display}}">
|
|
||||||
<meta http-equiv="refresh" content="0; url=https://pkg.go.dev/{{.Import}}/{{.Subpath}}">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
Nothing to see here; <a href="https://pkg.go.dev/{{.Import}}/{{.Subpath}}">see the package on pkg.go.dev</a>.
|
|
||||||
</body>
|
|
||||||
</html>`))
|
|
||||||
|
|
||||||
type pathConfigSet []pathConfig
|
|
||||||
|
|
||||||
func (pset pathConfigSet) Len() int {
|
|
||||||
return len(pset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pset pathConfigSet) Less(i, j int) bool {
|
|
||||||
return pset[i].path < pset[j].path
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pset pathConfigSet) Swap(i, j int) {
|
|
||||||
pset[i], pset[j] = pset[j], pset[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pset pathConfigSet) find(path string) (pc *pathConfig, subpath string) {
|
|
||||||
// Fast path with binary search to retrieve exact matches
|
|
||||||
// e.g. given pset ["/", "/abc", "/xyz"], path "/def" won't match.
|
|
||||||
i := sort.Search(len(pset), func(i int) bool {
|
|
||||||
return pset[i].path >= path
|
|
||||||
})
|
|
||||||
if i < len(pset) && pset[i].path == path {
|
|
||||||
return &pset[i], ""
|
|
||||||
}
|
|
||||||
if i > 0 && strings.HasPrefix(path, pset[i-1].path+"/") {
|
|
||||||
return &pset[i-1], path[len(pset[i-1].path)+1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Slow path, now looking for the longest prefix/shortest subpath i.e.
|
|
||||||
// e.g. given pset ["/", "/abc/", "/abc/def/", "/xyz"/]
|
|
||||||
// * query "/abc/foo" returns "/abc/" with a subpath of "foo"
|
|
||||||
// * query "/x" returns "/" with a subpath of "x"
|
|
||||||
lenShortestSubpath := len(path)
|
|
||||||
var bestMatchConfig *pathConfig
|
|
||||||
|
|
||||||
// After binary search with the >= lexicographic comparison,
|
|
||||||
// nothing greater than i will be a prefix of path.
|
|
||||||
max := i
|
|
||||||
for i := 0; i < max; i++ {
|
|
||||||
ps := pset[i]
|
|
||||||
if len(ps.path) >= len(path) {
|
|
||||||
// We previously didn't find the path by search, so any
|
|
||||||
// route with equal or greater length is NOT a match.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sSubpath := strings.TrimPrefix(path, ps.path)
|
|
||||||
if len(sSubpath) < lenShortestSubpath {
|
|
||||||
subpath = sSubpath
|
|
||||||
lenShortestSubpath = len(sSubpath)
|
|
||||||
bestMatchConfig = &pset[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bestMatchConfig, subpath
|
|
||||||
}
|
|
||||||
@@ -1,315 +0,0 @@
|
|||||||
// Copyright 2017 Google Inc. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"sort"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHandler(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
config string
|
|
||||||
path string
|
|
||||||
|
|
||||||
goImport string
|
|
||||||
goSource string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "explicit display",
|
|
||||||
config: "host: example.com\n" +
|
|
||||||
"paths:\n" +
|
|
||||||
" /portmidi:\n" +
|
|
||||||
" repo: https://github.com/rakyll/portmidi\n" +
|
|
||||||
" display: https://github.com/rakyll/portmidi _ _\n",
|
|
||||||
path: "/portmidi",
|
|
||||||
goImport: "example.com/portmidi git https://github.com/rakyll/portmidi",
|
|
||||||
goSource: "example.com/portmidi https://github.com/rakyll/portmidi _ _",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "display GitHub inference",
|
|
||||||
config: "host: example.com\n" +
|
|
||||||
"paths:\n" +
|
|
||||||
" /portmidi:\n" +
|
|
||||||
" repo: https://github.com/rakyll/portmidi\n",
|
|
||||||
path: "/portmidi",
|
|
||||||
goImport: "example.com/portmidi git https://github.com/rakyll/portmidi",
|
|
||||||
goSource: "example.com/portmidi https://github.com/rakyll/portmidi https://github.com/rakyll/portmidi/tree/master{/dir} https://github.com/rakyll/portmidi/blob/master{/dir}/{file}#L{line}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Bitbucket Mercurial",
|
|
||||||
config: "host: example.com\n" +
|
|
||||||
"paths:\n" +
|
|
||||||
" /gopdf:\n" +
|
|
||||||
" repo: https://bitbucket.org/zombiezen/gopdf\n" +
|
|
||||||
" vcs: hg\n",
|
|
||||||
path: "/gopdf",
|
|
||||||
goImport: "example.com/gopdf hg https://bitbucket.org/zombiezen/gopdf",
|
|
||||||
goSource: "example.com/gopdf https://bitbucket.org/zombiezen/gopdf https://bitbucket.org/zombiezen/gopdf/src/default{/dir} https://bitbucket.org/zombiezen/gopdf/src/default{/dir}/{file}#{file}-{line}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Bitbucket Git",
|
|
||||||
config: "host: example.com\n" +
|
|
||||||
"paths:\n" +
|
|
||||||
" /mygit:\n" +
|
|
||||||
" repo: https://bitbucket.org/zombiezen/mygit\n" +
|
|
||||||
" vcs: git\n",
|
|
||||||
path: "/mygit",
|
|
||||||
goImport: "example.com/mygit git https://bitbucket.org/zombiezen/mygit",
|
|
||||||
goSource: "example.com/mygit https://bitbucket.org/zombiezen/mygit https://bitbucket.org/zombiezen/mygit/src/default{/dir} https://bitbucket.org/zombiezen/mygit/src/default{/dir}/{file}#{file}-{line}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "subpath",
|
|
||||||
config: "host: example.com\n" +
|
|
||||||
"paths:\n" +
|
|
||||||
" /portmidi:\n" +
|
|
||||||
" repo: https://github.com/rakyll/portmidi\n" +
|
|
||||||
" display: https://github.com/rakyll/portmidi _ _\n",
|
|
||||||
path: "/portmidi/foo",
|
|
||||||
goImport: "example.com/portmidi git https://github.com/rakyll/portmidi",
|
|
||||||
goSource: "example.com/portmidi https://github.com/rakyll/portmidi _ _",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "subpath with trailing config slash",
|
|
||||||
config: "host: example.com\n" +
|
|
||||||
"paths:\n" +
|
|
||||||
" /portmidi/:\n" +
|
|
||||||
" repo: https://github.com/rakyll/portmidi\n" +
|
|
||||||
" display: https://github.com/rakyll/portmidi _ _\n",
|
|
||||||
path: "/portmidi/foo",
|
|
||||||
goImport: "example.com/portmidi git https://github.com/rakyll/portmidi",
|
|
||||||
goSource: "example.com/portmidi https://github.com/rakyll/portmidi _ _",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, test := range tests {
|
|
||||||
h, err := newHandler([]byte(test.config))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%s: newHandler: %v", test.name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
s := httptest.NewServer(h)
|
|
||||||
resp, err := http.Get(s.URL + test.path)
|
|
||||||
if err != nil {
|
|
||||||
s.Close()
|
|
||||||
t.Errorf("%s: http.Get: %v", test.name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
|
||||||
resp.Body.Close()
|
|
||||||
s.Close()
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
t.Errorf("%s: status code = %s; want 200 OK", test.name, resp.Status)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%s: ioutil.ReadAll: %v", test.name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if got := findMeta(data, "go-import"); got != test.goImport {
|
|
||||||
t.Errorf("%s: meta go-import = %q; want %q", test.name, got, test.goImport)
|
|
||||||
}
|
|
||||||
if got := findMeta(data, "go-source"); got != test.goSource {
|
|
||||||
t.Errorf("%s: meta go-source = %q; want %q", test.name, got, test.goSource)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBadConfigs(t *testing.T) {
|
|
||||||
badConfigs := []string{
|
|
||||||
"paths:\n" +
|
|
||||||
" /missingvcs:\n" +
|
|
||||||
" repo: https://bitbucket.org/zombiezen/gopdf\n",
|
|
||||||
"paths:\n" +
|
|
||||||
" /unknownvcs:\n" +
|
|
||||||
" repo: https://bitbucket.org/zombiezen/gopdf\n" +
|
|
||||||
" vcs: xyzzy\n",
|
|
||||||
"cache_max_age: -1\n" +
|
|
||||||
"paths:\n" +
|
|
||||||
" /portmidi:\n" +
|
|
||||||
" repo: https://github.com/rakyll/portmidi\n",
|
|
||||||
}
|
|
||||||
for _, config := range badConfigs {
|
|
||||||
_, err := newHandler([]byte(config))
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("expected config to produce an error, but did not:\n%s", config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func findMeta(data []byte, name string) string {
|
|
||||||
var sep []byte
|
|
||||||
sep = append(sep, `<meta name="`...)
|
|
||||||
sep = append(sep, name...)
|
|
||||||
sep = append(sep, `" content="`...)
|
|
||||||
i := bytes.Index(data, sep)
|
|
||||||
if i == -1 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
content := data[i+len(sep):]
|
|
||||||
j := bytes.IndexByte(content, '"')
|
|
||||||
if j == -1 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return string(content[:j])
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPathConfigSetFind(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
paths []string
|
|
||||||
query string
|
|
||||||
want string
|
|
||||||
subpath string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
paths: []string{"/portmidi"},
|
|
||||||
query: "/portmidi",
|
|
||||||
want: "/portmidi",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/portmidi"},
|
|
||||||
query: "/portmidi/",
|
|
||||||
want: "/portmidi",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/portmidi"},
|
|
||||||
query: "/foo",
|
|
||||||
want: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/portmidi"},
|
|
||||||
query: "/zzz",
|
|
||||||
want: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/abc", "/portmidi", "/xyz"},
|
|
||||||
query: "/portmidi",
|
|
||||||
want: "/portmidi",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/abc", "/portmidi", "/xyz"},
|
|
||||||
query: "/portmidi/foo",
|
|
||||||
want: "/portmidi",
|
|
||||||
subpath: "foo",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/example/helloworld", "/", "/y", "/foo"},
|
|
||||||
query: "/x",
|
|
||||||
want: "/",
|
|
||||||
subpath: "x",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/example/helloworld", "/", "/y", "/foo"},
|
|
||||||
query: "/",
|
|
||||||
want: "/",
|
|
||||||
subpath: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/example/helloworld", "/", "/y", "/foo"},
|
|
||||||
query: "/example",
|
|
||||||
want: "/",
|
|
||||||
subpath: "example",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/example/helloworld", "/", "/y", "/foo"},
|
|
||||||
query: "/example/foo",
|
|
||||||
want: "/",
|
|
||||||
subpath: "example/foo",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/example/helloworld", "/", "/y", "/foo"},
|
|
||||||
query: "/y",
|
|
||||||
want: "/y",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/example/helloworld", "/", "/y", "/foo"},
|
|
||||||
query: "/x/y/",
|
|
||||||
want: "/",
|
|
||||||
subpath: "x/y/",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
paths: []string{"/example/helloworld", "/y", "/foo"},
|
|
||||||
query: "/x",
|
|
||||||
want: "",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
emptyToNil := func(s string) string {
|
|
||||||
if s == "" {
|
|
||||||
return "<nil>"
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
for _, test := range tests {
|
|
||||||
pset := make(pathConfigSet, len(test.paths))
|
|
||||||
for i := range test.paths {
|
|
||||||
pset[i].path = test.paths[i]
|
|
||||||
}
|
|
||||||
sort.Sort(pset)
|
|
||||||
pc, subpath := pset.find(test.query)
|
|
||||||
var got string
|
|
||||||
if pc != nil {
|
|
||||||
got = pc.path
|
|
||||||
}
|
|
||||||
if got != test.want || subpath != test.subpath {
|
|
||||||
t.Errorf("pathConfigSet(%v).find(%q) = %v, %v; want %v, %v",
|
|
||||||
test.paths, test.query, emptyToNil(got), subpath, emptyToNil(test.want), test.subpath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCacheHeader(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
config string
|
|
||||||
cacheControl string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "default",
|
|
||||||
cacheControl: "public, max-age=86400",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "specify time",
|
|
||||||
config: "cache_max_age: 60\n",
|
|
||||||
cacheControl: "public, max-age=60",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "zero",
|
|
||||||
config: "cache_max_age: 0\n",
|
|
||||||
cacheControl: "public, max-age=0",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, test := range tests {
|
|
||||||
h, err := newHandler([]byte("paths:\n /portmidi:\n repo: https://github.com/rakyll/portmidi\n" +
|
|
||||||
test.config))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%s: newHandler: %v", test.name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
s := httptest.NewServer(h)
|
|
||||||
resp, err := http.Get(s.URL + "/portmidi")
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%s: http.Get: %v", test.name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
resp.Body.Close()
|
|
||||||
got := resp.Header.Get("Cache-Control")
|
|
||||||
if got != test.cacheControl {
|
|
||||||
t.Errorf("%s: Cache-Control header = %q; want %q", test.name, got, test.cacheControl)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
// Copyright 2017 Google Inc. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
var configPath string
|
|
||||||
switch len(os.Args) {
|
|
||||||
case 1:
|
|
||||||
configPath = "vanity.yaml"
|
|
||||||
case 2:
|
|
||||||
configPath = os.Args[1]
|
|
||||||
default:
|
|
||||||
log.Fatal("usage: m3o-go-url [CONFIG]")
|
|
||||||
}
|
|
||||||
vanity, err := ioutil.ReadFile(configPath)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
h, err := newHandler(vanity)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
http.Handle("/", h)
|
|
||||||
|
|
||||||
port := os.Getenv("PORT")
|
|
||||||
if port == "" {
|
|
||||||
port = "8080"
|
|
||||||
}
|
|
||||||
if err := http.ListenAndServe(":"+port, nil); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultHost(r *http.Request) string {
|
|
||||||
return r.Host
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
host: go.m3o.com
|
|
||||||
|
|
||||||
paths:
|
|
||||||
/:
|
|
||||||
repo: https://github.com/m3o/m3o-go
|
|
||||||
@@ -1,200 +0,0 @@
|
|||||||
package contact
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Contact interface {
|
|
||||||
Create(*CreateRequest) (*CreateResponse, error)
|
|
||||||
Delete(*DeleteRequest) (*DeleteResponse, error)
|
|
||||||
List(*ListRequest) (*ListResponse, error)
|
|
||||||
Read(*ReadRequest) (*ReadResponse, error)
|
|
||||||
Update(*UpdateRequest) (*UpdateResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewContactService(token string) *ContactService {
|
|
||||||
return &ContactService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type ContactService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
func (t *ContactService) Create(request *CreateRequest) (*CreateResponse, error) {
|
|
||||||
|
|
||||||
rsp := &CreateResponse{}
|
|
||||||
return rsp, t.client.Call("contact", "Create", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
func (t *ContactService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
|
||||||
|
|
||||||
rsp := &DeleteResponse{}
|
|
||||||
return rsp, t.client.Call("contact", "Delete", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
func (t *ContactService) List(request *ListRequest) (*ListResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ListResponse{}
|
|
||||||
return rsp, t.client.Call("contact", "List", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
func (t *ContactService) Read(request *ReadRequest) (*ReadResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ReadResponse{}
|
|
||||||
return rsp, t.client.Call("contact", "Read", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
func (t *ContactService) Update(request *UpdateRequest) (*UpdateResponse, error) {
|
|
||||||
|
|
||||||
rsp := &UpdateResponse{}
|
|
||||||
return rsp, t.client.Call("contact", "Update", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type Address struct {
|
|
||||||
// the label of the address
|
|
||||||
Label string `json:"label"`
|
|
||||||
// the address location
|
|
||||||
Location string `json:"location"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ContactInfo struct {
|
|
||||||
// the address
|
|
||||||
Addresses []Address `json:"addresses"`
|
|
||||||
// the birthday
|
|
||||||
Birthday string `json:"birthday"`
|
|
||||||
// create date string in RFC3339
|
|
||||||
CreatedAt string `json:"created_at"`
|
|
||||||
// the emails
|
|
||||||
Emails []Email `json:"emails"`
|
|
||||||
// contact id
|
|
||||||
Id string `json:"id"`
|
|
||||||
// the contact links
|
|
||||||
Links []Link `json:"links"`
|
|
||||||
// the contact name
|
|
||||||
Name string `json:"name"`
|
|
||||||
// note of the contact
|
|
||||||
Note string `json:"note"`
|
|
||||||
// the phone numbers
|
|
||||||
Phones []Phone `json:"phones"`
|
|
||||||
// the social media username
|
|
||||||
SocialMedias *SocialMedia `json:"social_medias"`
|
|
||||||
// update date string in RFC3339
|
|
||||||
UpdatedAt string `json:"updated_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateRequest struct {
|
|
||||||
// optional, location
|
|
||||||
Addresses []Address `json:"addresses"`
|
|
||||||
// optional, birthday
|
|
||||||
Birthday string `json:"birthday"`
|
|
||||||
// optional, emails
|
|
||||||
Emails []Email `json:"emails"`
|
|
||||||
// optional, links
|
|
||||||
Links []Link `json:"links"`
|
|
||||||
// required, the name of the contact
|
|
||||||
Name string `json:"name"`
|
|
||||||
// optional, note of the contact
|
|
||||||
Note string `json:"note"`
|
|
||||||
// optional, phone numbers
|
|
||||||
Phones []Phone `json:"phones"`
|
|
||||||
// optional, social media
|
|
||||||
SocialMedias *SocialMedia `json:"social_medias"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateResponse struct {
|
|
||||||
Contact *ContactInfo `json:"contact"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteRequest struct {
|
|
||||||
// the id of the contact
|
|
||||||
Id string `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteResponse struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type Email struct {
|
|
||||||
// the email address
|
|
||||||
Address string `json:"address"`
|
|
||||||
// the label of the email
|
|
||||||
Label string `json:"label"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Link struct {
|
|
||||||
// the label of the link
|
|
||||||
Label string `json:"label"`
|
|
||||||
// the url of the contact
|
|
||||||
Url string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListRequest struct {
|
|
||||||
// optional, default is 30
|
|
||||||
Limit int32 `json:"limit"`
|
|
||||||
// optional
|
|
||||||
Offset int32 `json:"offset"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListResponse struct {
|
|
||||||
Contacts []ContactInfo `json:"contacts"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Phone struct {
|
|
||||||
// the label of the phone number
|
|
||||||
Label string `json:"label"`
|
|
||||||
// phone number
|
|
||||||
Number string `json:"number"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReadRequest struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReadResponse struct {
|
|
||||||
Contact *ContactInfo `json:"contact"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SocialMedia struct {
|
|
||||||
// the label of the social
|
|
||||||
Label string `json:"label"`
|
|
||||||
// the username of social media
|
|
||||||
Username string `json:"username"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateRequest struct {
|
|
||||||
// optional, addresses
|
|
||||||
Addresses []Address `json:"addresses"`
|
|
||||||
// optional, birthday
|
|
||||||
Birthday string `json:"birthday"`
|
|
||||||
// optional, emails
|
|
||||||
Emails []Email `json:"emails"`
|
|
||||||
// required, the contact id
|
|
||||||
Id string `json:"id"`
|
|
||||||
// optional, links
|
|
||||||
Links []Link `json:"links"`
|
|
||||||
// required, the name
|
|
||||||
Name string `json:"name"`
|
|
||||||
// optional, note
|
|
||||||
Note string `json:"note"`
|
|
||||||
// optional, phone number
|
|
||||||
Phones []Phone `json:"phones"`
|
|
||||||
// optional, social media
|
|
||||||
SocialMedias *SocialMedia `json:"social_medias"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateResponse struct {
|
|
||||||
Contact *ContactInfo `json:"contact"`
|
|
||||||
}
|
|
||||||
135
crypto/crypto.go
135
crypto/crypto.go
@@ -1,135 +0,0 @@
|
|||||||
package crypto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Crypto interface {
|
|
||||||
History(*HistoryRequest) (*HistoryResponse, error)
|
|
||||||
News(*NewsRequest) (*NewsResponse, error)
|
|
||||||
Price(*PriceRequest) (*PriceResponse, error)
|
|
||||||
Quote(*QuoteRequest) (*QuoteResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCryptoService(token string) *CryptoService {
|
|
||||||
return &CryptoService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type CryptoService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the history for the previous close
|
|
||||||
func (t *CryptoService) History(request *HistoryRequest) (*HistoryResponse, error) {
|
|
||||||
|
|
||||||
rsp := &HistoryResponse{}
|
|
||||||
return rsp, t.client.Call("crypto", "History", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get news related to a currency
|
|
||||||
func (t *CryptoService) News(request *NewsRequest) (*NewsResponse, error) {
|
|
||||||
|
|
||||||
rsp := &NewsResponse{}
|
|
||||||
return rsp, t.client.Call("crypto", "News", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the last price for a given crypto ticker
|
|
||||||
func (t *CryptoService) Price(request *PriceRequest) (*PriceResponse, error) {
|
|
||||||
|
|
||||||
rsp := &PriceResponse{}
|
|
||||||
return rsp, t.client.Call("crypto", "Price", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the last quote for a given crypto ticker
|
|
||||||
func (t *CryptoService) Quote(request *QuoteRequest) (*QuoteResponse, error) {
|
|
||||||
|
|
||||||
rsp := &QuoteResponse{}
|
|
||||||
return rsp, t.client.Call("crypto", "Quote", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type Article struct {
|
|
||||||
// the date published
|
|
||||||
Date string `json:"date"`
|
|
||||||
// its description
|
|
||||||
Description string `json:"description"`
|
|
||||||
// the source
|
|
||||||
Source string `json:"source"`
|
|
||||||
// title of the article
|
|
||||||
Title string `json:"title"`
|
|
||||||
// the source url
|
|
||||||
Url string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type HistoryRequest struct {
|
|
||||||
// the crypto symbol e.g BTCUSD
|
|
||||||
Symbol string `json:"symbol"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type HistoryResponse struct {
|
|
||||||
// the close price
|
|
||||||
Close float64 `json:"close"`
|
|
||||||
// the date
|
|
||||||
Date string `json:"date"`
|
|
||||||
// the peak price
|
|
||||||
High float64 `json:"high"`
|
|
||||||
// the low price
|
|
||||||
Low float64 `json:"low"`
|
|
||||||
// the open price
|
|
||||||
Open float64 `json:"open"`
|
|
||||||
// the crypto symbol
|
|
||||||
Symbol string `json:"symbol"`
|
|
||||||
// the volume
|
|
||||||
Volume float64 `json:"volume"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NewsRequest struct {
|
|
||||||
// cryptocurrency ticker to request news for e.g BTC
|
|
||||||
Symbol string `json:"symbol"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NewsResponse struct {
|
|
||||||
// list of articles
|
|
||||||
Articles []Article `json:"articles"`
|
|
||||||
// symbol requested for
|
|
||||||
Symbol string `json:"symbol"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PriceRequest struct {
|
|
||||||
// the crypto symbol e.g BTCUSD
|
|
||||||
Symbol string `json:"symbol"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PriceResponse struct {
|
|
||||||
// the last price
|
|
||||||
Price float64 `json:"price"`
|
|
||||||
// the crypto symbol e.g BTCUSD
|
|
||||||
Symbol string `json:"symbol"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type QuoteRequest struct {
|
|
||||||
// the crypto symbol e.g BTCUSD
|
|
||||||
Symbol string `json:"symbol"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type QuoteResponse struct {
|
|
||||||
// the asking price
|
|
||||||
AskPrice float64 `json:"ask_price"`
|
|
||||||
// the ask size
|
|
||||||
AskSize float64 `json:"ask_size"`
|
|
||||||
// the bidding price
|
|
||||||
BidPrice float64 `json:"bid_price"`
|
|
||||||
// the bid size
|
|
||||||
BidSize float64 `json:"bid_size"`
|
|
||||||
// the crypto symbol
|
|
||||||
Symbol string `json:"symbol"`
|
|
||||||
// the UTC timestamp of the quote
|
|
||||||
Timestamp string `json:"timestamp"`
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
package currency
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Currency interface {
|
|
||||||
Codes(*CodesRequest) (*CodesResponse, error)
|
|
||||||
Convert(*ConvertRequest) (*ConvertResponse, error)
|
|
||||||
History(*HistoryRequest) (*HistoryResponse, error)
|
|
||||||
Rates(*RatesRequest) (*RatesResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCurrencyService(token string) *CurrencyService {
|
|
||||||
return &CurrencyService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type CurrencyService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Codes returns the supported currency codes for the API
|
|
||||||
func (t *CurrencyService) Codes(request *CodesRequest) (*CodesResponse, error) {
|
|
||||||
|
|
||||||
rsp := &CodesResponse{}
|
|
||||||
return rsp, t.client.Call("currency", "Codes", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
||||||
func (t *CurrencyService) Convert(request *ConvertRequest) (*ConvertResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ConvertResponse{}
|
|
||||||
return rsp, t.client.Call("currency", "Convert", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the historic rates for a currency on a given date
|
|
||||||
func (t *CurrencyService) History(request *HistoryRequest) (*HistoryResponse, error) {
|
|
||||||
|
|
||||||
rsp := &HistoryResponse{}
|
|
||||||
return rsp, t.client.Call("currency", "History", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rates returns the currency rates for a given code e.g USD
|
|
||||||
func (t *CurrencyService) Rates(request *RatesRequest) (*RatesResponse, error) {
|
|
||||||
|
|
||||||
rsp := &RatesResponse{}
|
|
||||||
return rsp, t.client.Call("currency", "Rates", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type Code struct {
|
|
||||||
// e.g United States Dollar
|
|
||||||
Currency string `json:"currency"`
|
|
||||||
// e.g USD
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CodesRequest struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type CodesResponse struct {
|
|
||||||
Codes []Code `json:"codes"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConvertRequest struct {
|
|
||||||
// optional amount to convert e.g 10.0
|
|
||||||
Amount float64 `json:"amount"`
|
|
||||||
// base code to convert from e.g USD
|
|
||||||
From string `json:"from"`
|
|
||||||
// target code to convert to e.g GBP
|
|
||||||
To string `json:"to"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConvertResponse struct {
|
|
||||||
// converted amount e.g 7.10
|
|
||||||
Amount float64 `json:"amount"`
|
|
||||||
// the base code e.g USD
|
|
||||||
From string `json:"from"`
|
|
||||||
// conversion rate e.g 0.71
|
|
||||||
Rate float64 `json:"rate"`
|
|
||||||
// the target code e.g GBP
|
|
||||||
To string `json:"to"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type HistoryRequest struct {
|
|
||||||
// currency code e.g USD
|
|
||||||
Code string `json:"code"`
|
|
||||||
// date formatted as YYYY-MM-DD
|
|
||||||
Date string `json:"date"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type HistoryResponse struct {
|
|
||||||
// The code of the request
|
|
||||||
Code string `json:"code"`
|
|
||||||
// The date requested
|
|
||||||
Date string `json:"date"`
|
|
||||||
// The rate for the day as code:rate
|
|
||||||
Rates map[string]float64 `json:"rates"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RatesRequest struct {
|
|
||||||
// The currency code to get rates for e.g USD
|
|
||||||
Code string `json:"code"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RatesResponse struct {
|
|
||||||
// The code requested e.g USD
|
|
||||||
Code string `json:"code"`
|
|
||||||
// The rates for the given code as key-value pairs code:rate
|
|
||||||
Rates map[string]float64 `json:"rates"`
|
|
||||||
}
|
|
||||||
205
db/db.go
205
db/db.go
@@ -1,205 +0,0 @@
|
|||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Db interface {
|
|
||||||
Count(*CountRequest) (*CountResponse, error)
|
|
||||||
Create(*CreateRequest) (*CreateResponse, error)
|
|
||||||
Delete(*DeleteRequest) (*DeleteResponse, error)
|
|
||||||
DropTable(*DropTableRequest) (*DropTableResponse, error)
|
|
||||||
ListTables(*ListTablesRequest) (*ListTablesResponse, error)
|
|
||||||
Read(*ReadRequest) (*ReadResponse, error)
|
|
||||||
RenameTable(*RenameTableRequest) (*RenameTableResponse, error)
|
|
||||||
Truncate(*TruncateRequest) (*TruncateResponse, error)
|
|
||||||
Update(*UpdateRequest) (*UpdateResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDbService(token string) *DbService {
|
|
||||||
return &DbService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type DbService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Count records in a table
|
|
||||||
func (t *DbService) Count(request *CountRequest) (*CountResponse, error) {
|
|
||||||
|
|
||||||
rsp := &CountResponse{}
|
|
||||||
return rsp, t.client.Call("db", "Count", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
|
||||||
func (t *DbService) Create(request *CreateRequest) (*CreateResponse, error) {
|
|
||||||
|
|
||||||
rsp := &CreateResponse{}
|
|
||||||
return rsp, t.client.Call("db", "Create", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete a record in the database by id.
|
|
||||||
func (t *DbService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
|
||||||
|
|
||||||
rsp := &DeleteResponse{}
|
|
||||||
return rsp, t.client.Call("db", "Delete", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drop a table in the DB
|
|
||||||
func (t *DbService) DropTable(request *DropTableRequest) (*DropTableResponse, error) {
|
|
||||||
|
|
||||||
rsp := &DropTableResponse{}
|
|
||||||
return rsp, t.client.Call("db", "DropTable", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// List tables in the DB
|
|
||||||
func (t *DbService) ListTables(request *ListTablesRequest) (*ListTablesResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ListTablesResponse{}
|
|
||||||
return rsp, t.client.Call("db", "ListTables", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read data from a table. Lookup can be by ID or via querying any field in the record.
|
|
||||||
func (t *DbService) Read(request *ReadRequest) (*ReadResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ReadResponse{}
|
|
||||||
return rsp, t.client.Call("db", "Read", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rename a table
|
|
||||||
func (t *DbService) RenameTable(request *RenameTableRequest) (*RenameTableResponse, error) {
|
|
||||||
|
|
||||||
rsp := &RenameTableResponse{}
|
|
||||||
return rsp, t.client.Call("db", "RenameTable", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Truncate the records in a table
|
|
||||||
func (t *DbService) Truncate(request *TruncateRequest) (*TruncateResponse, error) {
|
|
||||||
|
|
||||||
rsp := &TruncateResponse{}
|
|
||||||
return rsp, t.client.Call("db", "Truncate", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update a record in the database. Include an "id" in the record to update.
|
|
||||||
func (t *DbService) Update(request *UpdateRequest) (*UpdateResponse, error) {
|
|
||||||
|
|
||||||
rsp := &UpdateResponse{}
|
|
||||||
return rsp, t.client.Call("db", "Update", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type CountRequest struct {
|
|
||||||
// specify the table name
|
|
||||||
Table string `json:"table"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CountResponse struct {
|
|
||||||
// the number of records in the table
|
|
||||||
Count int32 `json:"count"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateRequest struct {
|
|
||||||
// optional record id to use
|
|
||||||
Id string `json:"id"`
|
|
||||||
// JSON encoded record or records (can be array or object)
|
|
||||||
Record map[string]interface{} `json:"record"`
|
|
||||||
// Optional table name. Defaults to 'default'
|
|
||||||
Table string `json:"table"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateResponse struct {
|
|
||||||
// The id of the record (either specified or automatically created)
|
|
||||||
Id string `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteRequest struct {
|
|
||||||
// id of the record
|
|
||||||
Id string `json:"id"`
|
|
||||||
// Optional table name. Defaults to 'default'
|
|
||||||
Table string `json:"table"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteResponse struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type DropTableRequest struct {
|
|
||||||
Table string `json:"table"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DropTableResponse struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListTablesRequest struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListTablesResponse struct {
|
|
||||||
// list of tables
|
|
||||||
Tables []string `json:"tables"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReadRequest struct {
|
|
||||||
// Read by id. Equivalent to 'id == "your-id"'
|
|
||||||
Id string `json:"id"`
|
|
||||||
// Maximum number of records to return. Default limit is 25.
|
|
||||||
// Maximum limit is 1000. Anything higher will return an error.
|
|
||||||
Limit int32 `json:"limit"`
|
|
||||||
Offset int32 `json:"offset"`
|
|
||||||
// 'asc' (default), 'desc'
|
|
||||||
Order string `json:"order"`
|
|
||||||
// field name to order by
|
|
||||||
OrderBy string `json:"orderBy"`
|
|
||||||
// Examples: 'age >= 18', 'age >= 18 and verified == true'
|
|
||||||
// Comparison operators: '==', '!=', '<', '>', '<=', '>='
|
|
||||||
// Logical operator: 'and'
|
|
||||||
// Dot access is supported, eg: 'user.age == 11'
|
|
||||||
// Accessing list elements is not supported yet.
|
|
||||||
Query string `json:"query"`
|
|
||||||
// Optional table name. Defaults to 'default'
|
|
||||||
Table string `json:"table"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReadResponse struct {
|
|
||||||
// JSON encoded records
|
|
||||||
Records []map[string]interface{} `json:"records"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RenameTableRequest struct {
|
|
||||||
// current table name
|
|
||||||
From string `json:"from"`
|
|
||||||
// new table name
|
|
||||||
To string `json:"to"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RenameTableResponse struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type TruncateRequest struct {
|
|
||||||
Table string `json:"table"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TruncateResponse struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateRequest struct {
|
|
||||||
// The id of the record. If not specified it is inferred from the 'id' field of the record
|
|
||||||
Id string `json:"id"`
|
|
||||||
// record, JSON object
|
|
||||||
Record map[string]interface{} `json:"record"`
|
|
||||||
// Optional table name. Defaults to 'default'
|
|
||||||
Table string `json:"table"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateResponse struct {
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
package email
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Email interface {
|
|
||||||
Parse(*ParseRequest) (*ParseResponse, error)
|
|
||||||
Send(*SendRequest) (*SendResponse, error)
|
|
||||||
Validate(*ValidateRequest) (*ValidateResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEmailService(token string) *EmailService {
|
|
||||||
return &EmailService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
|
|
||||||
rsp := &SendResponse{}
|
|
||||||
return rsp, t.client.Call("email", "Send", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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"`
|
|
||||||
// the html body
|
|
||||||
HtmlBody string `json:"html_body"`
|
|
||||||
// an optional reply to email address
|
|
||||||
ReplyTo string `json:"reply_to"`
|
|
||||||
// the email subject
|
|
||||||
Subject string `json:"subject"`
|
|
||||||
// the text body
|
|
||||||
TextBody string `json:"text_body"`
|
|
||||||
// the email address of the recipient
|
|
||||||
To string `json:"to"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SendResponse struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type ValidateRequest struct {
|
|
||||||
Address string `json:"address"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ValidateResponse struct {
|
|
||||||
IsValid bool `json:"is_valid"`
|
|
||||||
}
|
|
||||||
101
emoji/emoji.go
101
emoji/emoji.go
@@ -1,101 +0,0 @@
|
|||||||
package emoji
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Emoji interface {
|
|
||||||
Find(*FindRequest) (*FindResponse, error)
|
|
||||||
Flag(*FlagRequest) (*FlagResponse, error)
|
|
||||||
Print(*PrintRequest) (*PrintResponse, error)
|
|
||||||
Send(*SendRequest) (*SendResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEmojiService(token string) *EmojiService {
|
|
||||||
return &EmojiService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type EmojiService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find an emoji by its alias e.g :beer:
|
|
||||||
func (t *EmojiService) Find(request *FindRequest) (*FindResponse, error) {
|
|
||||||
|
|
||||||
rsp := &FindResponse{}
|
|
||||||
return rsp, t.client.Call("emoji", "Find", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the flag for a country. Requires country code e.g GB for great britain
|
|
||||||
func (t *EmojiService) Flag(request *FlagRequest) (*FlagResponse, error) {
|
|
||||||
|
|
||||||
rsp := &FlagResponse{}
|
|
||||||
return rsp, t.client.Call("emoji", "Flag", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print text and renders the emojis with aliases e.g
|
|
||||||
// let's grab a :beer: becomes let's grab a 🍺
|
|
||||||
func (t *EmojiService) Print(request *PrintRequest) (*PrintResponse, error) {
|
|
||||||
|
|
||||||
rsp := &PrintResponse{}
|
|
||||||
return rsp, t.client.Call("emoji", "Print", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send an emoji to anyone via SMS. Messages are sent in the form '<message> Sent from <from>'
|
|
||||||
func (t *EmojiService) Send(request *SendRequest) (*SendResponse, error) {
|
|
||||||
|
|
||||||
rsp := &SendResponse{}
|
|
||||||
return rsp, t.client.Call("emoji", "Send", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type FindRequest struct {
|
|
||||||
// the alias code e.g :beer:
|
|
||||||
Alias string `json:"alias"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FindResponse struct {
|
|
||||||
// the unicode emoji 🍺
|
|
||||||
Emoji string `json:"emoji"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlagRequest struct {
|
|
||||||
// country code e.g GB
|
|
||||||
Code string `json:"code"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FlagResponse struct {
|
|
||||||
// the emoji flag
|
|
||||||
Flag string `json:"flag"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PrintRequest struct {
|
|
||||||
// text including any alias e.g let's grab a :beer:
|
|
||||||
Text string `json:"text"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PrintResponse struct {
|
|
||||||
// text with rendered emojis
|
|
||||||
Text string `json:"text"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SendRequest struct {
|
|
||||||
// the name of the sender from e.g Alice
|
|
||||||
From string `json:"from"`
|
|
||||||
// message to send including emoji aliases
|
|
||||||
Message string `json:"message"`
|
|
||||||
// phone number to send to (including international dialing code)
|
|
||||||
To string `json:"to"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SendResponse struct {
|
|
||||||
// whether or not it succeeded
|
|
||||||
Success bool `json:"success"`
|
|
||||||
}
|
|
||||||
@@ -1,249 +0,0 @@
|
|||||||
package evchargers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Evchargers interface {
|
|
||||||
ReferenceData(*ReferenceDataRequest) (*ReferenceDataResponse, error)
|
|
||||||
Search(*SearchRequest) (*SearchResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEvchargersService(token string) *EvchargersService {
|
|
||||||
return &EvchargersService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type EvchargersService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve reference data as used by this API and in conjunction with the Search endpoint
|
|
||||||
func (t *EvchargersService) ReferenceData(request *ReferenceDataRequest) (*ReferenceDataResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ReferenceDataResponse{}
|
|
||||||
return rsp, t.client.Call("evchargers", "ReferenceData", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search by giving a coordinate and a max distance, or bounding box and optional filters
|
|
||||||
func (t *EvchargersService) Search(request *SearchRequest) (*SearchResponse, error) {
|
|
||||||
|
|
||||||
rsp := &SearchResponse{}
|
|
||||||
return rsp, t.client.Call("evchargers", "Search", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type Address struct {
|
|
||||||
// Any comments about how to access the charger
|
|
||||||
AccessComments string `json:"access_comments"`
|
|
||||||
AddressLine1 string `json:"address_line_1"`
|
|
||||||
AddressLine2 string `json:"address_line_2"`
|
|
||||||
Country *Country `json:"country"`
|
|
||||||
CountryId string `json:"country_id"`
|
|
||||||
LatLng string `json:"lat_lng"`
|
|
||||||
Location *Coordinates `json:"location"`
|
|
||||||
Postcode string `json:"postcode"`
|
|
||||||
StateOrProvince string `json:"state_or_province"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Town string `json:"town"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type BoundingBox struct {
|
|
||||||
BottomLeft *Coordinates `json:"bottom_left"`
|
|
||||||
TopRight *Coordinates `json:"top_right"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChargerType struct {
|
|
||||||
Comments string `json:"comments"`
|
|
||||||
Id string `json:"id"`
|
|
||||||
// Is this 40KW+
|
|
||||||
IsFastChargeCapable bool `json:"is_fast_charge_capable"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CheckinStatusType struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
IsAutomated bool `json:"is_automated"`
|
|
||||||
IsPositive bool `json:"is_positive"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Connection struct {
|
|
||||||
// The amps offered
|
|
||||||
Amps float64 `json:"amps"`
|
|
||||||
ConnectionType *ConnectionType `json:"connection_type"`
|
|
||||||
// The ID of the connection type
|
|
||||||
ConnectionTypeId string `json:"connection_type_id"`
|
|
||||||
// The current
|
|
||||||
Current string `json:"current"`
|
|
||||||
Level *ChargerType `json:"level"`
|
|
||||||
// The level of charging power available
|
|
||||||
LevelId string `json:"level_id"`
|
|
||||||
// The power in KW
|
|
||||||
Power float64 `json:"power"`
|
|
||||||
Reference string `json:"reference"`
|
|
||||||
// The voltage offered
|
|
||||||
Voltage float64 `json:"voltage"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConnectionType struct {
|
|
||||||
FormalName string `json:"formal_name"`
|
|
||||||
Id string `json:"id"`
|
|
||||||
IsDiscontinued bool `json:"is_discontinued"`
|
|
||||||
IsObsolete bool `json:"is_obsolete"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Coordinates struct {
|
|
||||||
Latitude float64 `json:"latitude"`
|
|
||||||
Longitude float64 `json:"longitude"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Country struct {
|
|
||||||
ContinentCode string `json:"continent_code"`
|
|
||||||
Id string `json:"id"`
|
|
||||||
IsoCode string `json:"iso_code"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CurrentType struct {
|
|
||||||
Description string `json:"description"`
|
|
||||||
Id string `json:"id"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DataProvider struct {
|
|
||||||
Comments string `json:"comments"`
|
|
||||||
DataProviderStatusType *DataProviderStatusType `json:"data_provider_status_type"`
|
|
||||||
Id string `json:"id"`
|
|
||||||
// How is this data licensed
|
|
||||||
License string `json:"license"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Website string `json:"website"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DataProviderStatusType struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
IsProviderEnabled bool `json:"is_provider_enabled"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Operator struct {
|
|
||||||
Comments string `json:"comments"`
|
|
||||||
ContactEmail string `json:"contact_email"`
|
|
||||||
FaultReportEmail string `json:"fault_report_email"`
|
|
||||||
Id string `json:"id"`
|
|
||||||
// Is this operator a private individual vs a company
|
|
||||||
IsPrivateIndividual bool `json:"is_private_individual"`
|
|
||||||
PhonePrimary string `json:"phone_primary"`
|
|
||||||
PhoneSecondary string `json:"phone_secondary"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Website string `json:"website"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Poi struct {
|
|
||||||
// The address
|
|
||||||
Address *Address `json:"address"`
|
|
||||||
// The connections available at this charge point
|
|
||||||
Connections []Connection `json:"connections"`
|
|
||||||
// The cost of charging
|
|
||||||
Cost string `json:"cost"`
|
|
||||||
// The ID of the data provider
|
|
||||||
DataProviderId string `json:"data_provider_id"`
|
|
||||||
// The ID of the charger
|
|
||||||
Id string `json:"id"`
|
|
||||||
// The number of charging points
|
|
||||||
NumPoints int64 `json:"num_points,string"`
|
|
||||||
// The operator
|
|
||||||
Operator *Operator `json:"operator"`
|
|
||||||
// The ID of the operator of the charger
|
|
||||||
OperatorId string `json:"operator_id"`
|
|
||||||
// The type of usage
|
|
||||||
UsageType *UsageType `json:"usage_type"`
|
|
||||||
// The type of usage for this charger point (is it public, membership required, etc)
|
|
||||||
UsageTypeId string `json:"usage_type_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReferenceDataRequest struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReferenceDataResponse struct {
|
|
||||||
// The types of charger
|
|
||||||
ChargerTypes *ChargerType `json:"charger_types"`
|
|
||||||
// The types of checkin status
|
|
||||||
CheckinStatusTypes *CheckinStatusType `json:"checkin_status_types"`
|
|
||||||
// The types of connection
|
|
||||||
ConnectionTypes *ConnectionType `json:"connection_types"`
|
|
||||||
// The countries
|
|
||||||
Countries []Country `json:"countries"`
|
|
||||||
// The types of current
|
|
||||||
CurrentTypes *CurrentType `json:"current_types"`
|
|
||||||
// The providers of the charger data
|
|
||||||
DataProviders *DataProvider `json:"data_providers"`
|
|
||||||
// The companies operating the chargers
|
|
||||||
Operators []Operator `json:"operators"`
|
|
||||||
// The status of the charger
|
|
||||||
StatusTypes *StatusType `json:"status_types"`
|
|
||||||
// The status of a submission
|
|
||||||
SubmissionStatusTypes *SubmissionStatusType `json:"submission_status_types"`
|
|
||||||
// The different types of usage
|
|
||||||
UsageTypes *UsageType `json:"usage_types"`
|
|
||||||
// The types of user comment
|
|
||||||
UserCommentTypes *UserCommentType `json:"user_comment_types"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SearchRequest struct {
|
|
||||||
// Bounding box to search within (top left and bottom right coordinates)
|
|
||||||
Box *BoundingBox `json:"box"`
|
|
||||||
// IDs of the connection type
|
|
||||||
ConnectionTypes string `json:"connection_types"`
|
|
||||||
// Country ID
|
|
||||||
CountryId string `json:"country_id"`
|
|
||||||
// Search distance from point in metres, defaults to 5000m
|
|
||||||
Distance int64 `json:"distance,string"`
|
|
||||||
// Supported charging levels
|
|
||||||
Levels []string `json:"levels"`
|
|
||||||
// Coordinates from which to begin search
|
|
||||||
Location *Coordinates `json:"location"`
|
|
||||||
// Maximum number of results to return, defaults to 100
|
|
||||||
MaxResults int64 `json:"max_results,string"`
|
|
||||||
// Minimum power in KW. Note: data not available for many chargers
|
|
||||||
MinPower int64 `json:"min_power,string"`
|
|
||||||
// IDs of the the EV charger operator
|
|
||||||
Operators []string `json:"operators"`
|
|
||||||
// Usage of the charge point (is it public, membership required, etc)
|
|
||||||
UsageTypes string `json:"usage_types"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SearchResponse struct {
|
|
||||||
Pois []Poi `json:"pois"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type StatusType struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
IsOperational bool `json:"is_operational"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubmissionStatusType struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
IsLive bool `json:"is_live"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UsageType struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
IsAccessKeyRequired bool `json:"is_access_key_required"`
|
|
||||||
IsMembershipRequired bool `json:"is_membership_required"`
|
|
||||||
IsPayAtLocation bool `json:"is_pay_at_location"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserCommentType struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
116
event/event.go
116
event/event.go
@@ -1,116 +0,0 @@
|
|||||||
package event
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.m3o.com/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Event interface {
|
|
||||||
Consume(*ConsumeRequest) (*ConsumeResponseStream, error)
|
|
||||||
Publish(*PublishRequest) (*PublishResponse, error)
|
|
||||||
Read(*ReadRequest) (*ReadResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEventService(token string) *EventService {
|
|
||||||
return &EventService{
|
|
||||||
client: client.NewClient(&client.Options{
|
|
||||||
Token: token,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type EventService struct {
|
|
||||||
client *client.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consume events from a given topic.
|
|
||||||
func (t *EventService) Consume(request *ConsumeRequest) (*ConsumeResponseStream, error) {
|
|
||||||
stream, err := t.client.Stream("event", "Consume", request)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &ConsumeResponseStream{
|
|
||||||
stream: stream,
|
|
||||||
}, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConsumeResponseStream struct {
|
|
||||||
stream *client.Stream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ConsumeResponseStream) Recv() (*ConsumeResponse, error) {
|
|
||||||
var rsp ConsumeResponse
|
|
||||||
if err := t.stream.Recv(&rsp); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &rsp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Publish a event to the event stream.
|
|
||||||
func (t *EventService) Publish(request *PublishRequest) (*PublishResponse, error) {
|
|
||||||
|
|
||||||
rsp := &PublishResponse{}
|
|
||||||
return rsp, t.client.Call("event", "Publish", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read stored events
|
|
||||||
func (t *EventService) Read(request *ReadRequest) (*ReadResponse, error) {
|
|
||||||
|
|
||||||
rsp := &ReadResponse{}
|
|
||||||
return rsp, t.client.Call("event", "Read", request, rsp)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConsumeRequest struct {
|
|
||||||
// Optional group for the subscription
|
|
||||||
Group string `json:"group"`
|
|
||||||
// Optional offset to read from e.g "2006-01-02T15:04:05.999Z07:00"
|
|
||||||
Offset string `json:"offset"`
|
|
||||||
// The topic to subscribe to
|
|
||||||
Topic string `json:"topic"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConsumeResponse struct {
|
|
||||||
// Unique message id
|
|
||||||
Id string `json:"id"`
|
|
||||||
// The next json message on the topic
|
|
||||||
Message map[string]interface{} `json:"message"`
|
|
||||||
// Timestamp of publishing
|
|
||||||
Timestamp string `json:"timestamp"`
|
|
||||||
// The topic subscribed to
|
|
||||||
Topic string `json:"topic"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Ev struct {
|
|
||||||
// event id
|
|
||||||
Id string `json:"id"`
|
|
||||||
// event message
|
|
||||||
Message map[string]interface{} `json:"message"`
|
|
||||||
// event timestamp
|
|
||||||
Timestamp string `json:"timestamp"`
|
|
||||||
}
|
|
||||||
|
|
||||||
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 ReadRequest struct {
|
|
||||||
// number of events to read; default 25
|
|
||||||
Limit int32 `json:"limit"`
|
|
||||||
// offset for the events; default 0
|
|
||||||
Offset int32 `json:"offset"`
|
|
||||||
// topic to read from
|
|
||||||
Topic string `json:"topic"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReadResponse struct {
|
|
||||||
// the events
|
|
||||||
Events []Ev `json:"events"`
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# Address
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/address/api](https://m3o.com/address/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## LookupPostcode
|
|
||||||
|
|
||||||
Lookup a list of UK addresses by postcode
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/address/api#LookupPostcode](https://m3o.com/address/api#LookupPostcode)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/address"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Lookup a list of UK addresses by postcode
|
|
||||||
func LookupPostcode() {
|
|
||||||
addressService := address.NewAddressService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := addressService.LookupPostcode(&address.LookupPostcodeRequest{
|
|
||||||
Postcode: "SW1A 2AA",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/address"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Lookup a list of UK addresses by postcode
|
|
||||||
func LookupPostcode() {
|
|
||||||
addressService := address.NewAddressService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := addressService.LookupPostcode(&address.LookupPostcodeRequest{
|
|
||||||
Postcode: "SW1A 2AA",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/address"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Lookup a list of UK addresses by postcode
|
|
||||||
func main() {
|
|
||||||
addressService := address.NewAddressService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := addressService.LookupPostcode(&address.LookupPostcodeRequest{
|
|
||||||
Postcode: "SW1A 2AA",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# Answer
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/answer/api](https://m3o.com/answer/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## Question
|
|
||||||
|
|
||||||
Ask a question and receive an instant answer
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/answer/api#Question](https://m3o.com/answer/api#Question)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/answer"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ask a question and receive an instant answer
|
|
||||||
func AskAquestion() {
|
|
||||||
answerService := answer.NewAnswerService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := answerService.Question(&answer.QuestionRequest{
|
|
||||||
Query: "microsoft",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/answer"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ask a question and receive an instant answer
|
|
||||||
func AskAquestion() {
|
|
||||||
answerService := answer.NewAnswerService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := answerService.Question(&answer.QuestionRequest{
|
|
||||||
Query: "microsoft",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/answer"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ask a question and receive an instant answer
|
|
||||||
func main() {
|
|
||||||
answerService := answer.NewAnswerService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := answerService.Question(&answer.QuestionRequest{
|
|
||||||
Query: "microsoft",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,232 +0,0 @@
|
|||||||
# App
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/app/api](https://m3o.com/app/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## List
|
|
||||||
|
|
||||||
List all the apps
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/app/api#List](https://m3o.com/app/api#List)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// List all the apps
|
|
||||||
func ListTheApps() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.List(&app.ListRequest{
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Run
|
|
||||||
|
|
||||||
Run an app from source
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/app/api#Run](https://m3o.com/app/api#Run)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Run an app from source
|
|
||||||
func RunAnApp() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Run(&app.RunRequest{
|
|
||||||
Branch: "master",
|
|
||||||
Name: "helloworld",
|
|
||||||
Port: 8080,
|
|
||||||
Region: "europe-west1",
|
|
||||||
Repo: "github.com/asim/helloworld",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Regions
|
|
||||||
|
|
||||||
Return the support regions
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/app/api#Regions](https://m3o.com/app/api#Regions)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Return the support regions
|
|
||||||
func ListRegions() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Regions(&app.RegionsRequest{
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Status
|
|
||||||
|
|
||||||
Get the status of an app
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/app/api#Status](https://m3o.com/app/api#Status)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get the status of an app
|
|
||||||
func GetTheStatusOfAnApp() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Status(&app.StatusRequest{
|
|
||||||
Name: "helloworld",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Resolve
|
|
||||||
|
|
||||||
Resolve an app by id to its raw backend endpoint
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/app/api#Resolve](https://m3o.com/app/api#Resolve)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Resolve an app by id to its raw backend endpoint
|
|
||||||
func ResolveAppById() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Resolve(&app.ResolveRequest{
|
|
||||||
Id: "helloworld",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Update
|
|
||||||
|
|
||||||
Update the app. The latest source code will be downloaded, built and deployed.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/app/api#Update](https://m3o.com/app/api#Update)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Update the app. The latest source code will be downloaded, built and deployed.
|
|
||||||
func UpdateAnApp() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Update(&app.UpdateRequest{
|
|
||||||
Name: "helloworld",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Delete
|
|
||||||
|
|
||||||
Delete an app
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/app/api#Delete](https://m3o.com/app/api#Delete)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete an app
|
|
||||||
func DeleteAnApp() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Delete(&app.DeleteRequest{
|
|
||||||
Name: "helloworld",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Reserve
|
|
||||||
|
|
||||||
Reserve apps beyond the free quota. Call Run after.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/app/api#Reserve](https://m3o.com/app/api#Reserve)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reserve apps beyond the free quota. Call Run after.
|
|
||||||
func ReserveAppName() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Reserve(&app.ReserveRequest{
|
|
||||||
Name: "helloworld",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete an app
|
|
||||||
func main() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Delete(&app.DeleteRequest{
|
|
||||||
Name: "helloworld",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// List all the apps
|
|
||||||
func main() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.List(&app.ListRequest{})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Return the support regions
|
|
||||||
func main() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Regions(&app.RegionsRequest{})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reserve apps beyond the free quota. Call Run after.
|
|
||||||
func main() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Reserve(&app.ReserveRequest{
|
|
||||||
Name: "helloworld",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Resolve an app by id to its raw backend endpoint
|
|
||||||
func main() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Resolve(&app.ResolveRequest{
|
|
||||||
Id: "helloworld",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Run an app from source
|
|
||||||
func main() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Run(&app.RunRequest{
|
|
||||||
Branch: "master",
|
|
||||||
Name: "helloworld",
|
|
||||||
Port: 8080,
|
|
||||||
Region: "europe-west1",
|
|
||||||
Repo: "github.com/asim/helloworld",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get the status of an app
|
|
||||||
func main() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Status(&app.StatusRequest{
|
|
||||||
Name: "helloworld",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Update the app. The latest source code will be downloaded, built and deployed.
|
|
||||||
func main() {
|
|
||||||
appService := app.NewAppService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := appService.Update(&app.UpdateRequest{
|
|
||||||
Name: "helloworld",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
# Avatar
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/avatar/api](https://m3o.com/avatar/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## Generate
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/avatar/api#Generate](https://m3o.com/avatar/api#Generate)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/avatar"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func GenerateAvatarAndReturnBase64stringOfTheAvatar() {
|
|
||||||
avatarService := avatar.NewAvatarService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := avatarService.Generate(&avatar.GenerateRequest{
|
|
||||||
Format: "jpeg",
|
|
||||||
Gender: "female",
|
|
||||||
Upload: false,
|
|
||||||
Username: "",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Generate
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/avatar/api#Generate](https://m3o.com/avatar/api#Generate)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/avatar"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func GenerateAnAvatarAndUploadTheAvatarToMicrosCdn() {
|
|
||||||
avatarService := avatar.NewAvatarService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := avatarService.Generate(&avatar.GenerateRequest{
|
|
||||||
Format: "png",
|
|
||||||
Gender: "female",
|
|
||||||
Upload: true,
|
|
||||||
Username: "",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/avatar"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func main() {
|
|
||||||
avatarService := avatar.NewAvatarService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := avatarService.Generate(&avatar.GenerateRequest{
|
|
||||||
Format: "png",
|
|
||||||
Gender: "female",
|
|
||||||
Upload: true,
|
|
||||||
Username: "",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/avatar"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func main() {
|
|
||||||
avatarService := avatar.NewAvatarService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := avatarService.Generate(&avatar.GenerateRequest{
|
|
||||||
Format: "jpeg",
|
|
||||||
Gender: "female",
|
|
||||||
Upload: false,
|
|
||||||
Username: "",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
176
examples/cache/README.md
vendored
176
examples/cache/README.md
vendored
@@ -1,176 +0,0 @@
|
|||||||
# Cache
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/cache/api](https://m3o.com/cache/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## Increment
|
|
||||||
|
|
||||||
Increment a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/cache/api#Increment](https://m3o.com/cache/api#Increment)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Increment a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
func IncrementAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Increment(&cache.IncrementRequest{
|
|
||||||
Key: "counter",
|
|
||||||
Value: 2,
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Decrement
|
|
||||||
|
|
||||||
Decrement a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/cache/api#Decrement](https://m3o.com/cache/api#Decrement)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Decrement a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
func DecrementAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Decrement(&cache.DecrementRequest{
|
|
||||||
Key: "counter",
|
|
||||||
Value: 2,
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## ListKeys
|
|
||||||
|
|
||||||
List all the available keys
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/cache/api#ListKeys](https://m3o.com/cache/api#ListKeys)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// List all the available keys
|
|
||||||
func ListTheKeys() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.ListKeys(&cache.ListKeysRequest{
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Set
|
|
||||||
|
|
||||||
Set an item in the cache. Overwrites any existing value already set.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/cache/api#Set](https://m3o.com/cache/api#Set)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Set an item in the cache. Overwrites any existing value already set.
|
|
||||||
func SetAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Set(&cache.SetRequest{
|
|
||||||
Key: "foo",
|
|
||||||
Value: "bar",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Get
|
|
||||||
|
|
||||||
Get an item from the cache by key. If key is not found, an empty response is returned.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/cache/api#Get](https://m3o.com/cache/api#Get)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get an item from the cache by key. If key is not found, an empty response is returned.
|
|
||||||
func GetAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Get(&cache.GetRequest{
|
|
||||||
Key: "foo",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Delete
|
|
||||||
|
|
||||||
Delete a value from the cache. If key not found a success response is returned.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/cache/api#Delete](https://m3o.com/cache/api#Delete)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete a value from the cache. If key not found a success response is returned.
|
|
||||||
func DeleteAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Delete(&cache.DeleteRequest{
|
|
||||||
Key: "foo",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
18
examples/cache/decrement/decrementAValue.go
vendored
18
examples/cache/decrement/decrementAValue.go
vendored
@@ -1,18 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Decrement a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
func DecrementAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Decrement(&cache.DecrementRequest{
|
|
||||||
Key: "counter",
|
|
||||||
Value: 2,
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
18
examples/cache/decrement/decrementAValue/main.go
vendored
18
examples/cache/decrement/decrementAValue/main.go
vendored
@@ -1,18 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Decrement a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
func main() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Decrement(&cache.DecrementRequest{
|
|
||||||
Key: "counter",
|
|
||||||
Value: 2,
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
17
examples/cache/delete/deleteAValue.go
vendored
17
examples/cache/delete/deleteAValue.go
vendored
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete a value from the cache. If key not found a success response is returned.
|
|
||||||
func DeleteAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Delete(&cache.DeleteRequest{
|
|
||||||
Key: "foo",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
17
examples/cache/delete/deleteAValue/main.go
vendored
17
examples/cache/delete/deleteAValue/main.go
vendored
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete a value from the cache. If key not found a success response is returned.
|
|
||||||
func main() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Delete(&cache.DeleteRequest{
|
|
||||||
Key: "foo",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
17
examples/cache/get/getAValue.go
vendored
17
examples/cache/get/getAValue.go
vendored
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get an item from the cache by key. If key is not found, an empty response is returned.
|
|
||||||
func GetAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Get(&cache.GetRequest{
|
|
||||||
Key: "foo",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
17
examples/cache/get/getAValue/main.go
vendored
17
examples/cache/get/getAValue/main.go
vendored
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get an item from the cache by key. If key is not found, an empty response is returned.
|
|
||||||
func main() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Get(&cache.GetRequest{
|
|
||||||
Key: "foo",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
18
examples/cache/increment/incrementAValue.go
vendored
18
examples/cache/increment/incrementAValue.go
vendored
@@ -1,18 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Increment a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
func IncrementAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Increment(&cache.IncrementRequest{
|
|
||||||
Key: "counter",
|
|
||||||
Value: 2,
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
18
examples/cache/increment/incrementAValue/main.go
vendored
18
examples/cache/increment/incrementAValue/main.go
vendored
@@ -1,18 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Increment a value (if it's a number). If key not found it is equivalent to set.
|
|
||||||
func main() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Increment(&cache.IncrementRequest{
|
|
||||||
Key: "counter",
|
|
||||||
Value: 2,
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
15
examples/cache/listKeys/listTheKeys/main.go
vendored
15
examples/cache/listKeys/listTheKeys/main.go
vendored
@@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// List all the available keys
|
|
||||||
func main() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.ListKeys(&cache.ListKeysRequest{})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
18
examples/cache/set/setAValue.go
vendored
18
examples/cache/set/setAValue.go
vendored
@@ -1,18 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Set an item in the cache. Overwrites any existing value already set.
|
|
||||||
func SetAvalue() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Set(&cache.SetRequest{
|
|
||||||
Key: "foo",
|
|
||||||
Value: "bar",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
0
examples/cache/set/setAValue/.run
vendored
0
examples/cache/set/setAValue/.run
vendored
18
examples/cache/set/setAValue/main.go
vendored
18
examples/cache/set/setAValue/main.go
vendored
@@ -1,18 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Set an item in the cache. Overwrites any existing value already set.
|
|
||||||
func main() {
|
|
||||||
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cacheService.Set(&cache.SetRequest{
|
|
||||||
Key: "foo",
|
|
||||||
Value: "bar",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
# Carbon
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/carbon/api](https://m3o.com/carbon/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## Offset
|
|
||||||
|
|
||||||
Purchase 1KG (0.001 tonne) of carbon offsets in a single request
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/carbon/api#Offset](https://m3o.com/carbon/api#Offset)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/carbon"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Purchase 1KG (0.001 tonne) of carbon offsets in a single request
|
|
||||||
func OffsetCarbon() {
|
|
||||||
carbonService := carbon.NewCarbonService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := carbonService.Offset(&carbon.OffsetRequest{
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/carbon"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Purchase 1KG (0.001 tonne) of carbon offsets in a single request
|
|
||||||
func main() {
|
|
||||||
carbonService := carbon.NewCarbonService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := carbonService.Offset(&carbon.OffsetRequest{})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,219 +0,0 @@
|
|||||||
# Contact
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/contact/api](https://m3o.com/contact/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## Delete
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/contact/api#Delete](https://m3o.com/contact/api#Delete)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func DeleteAcontact() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.Delete(&contact.DeleteRequest{
|
|
||||||
Id: "42e48a3c-6221-11ec-96d2-acde48001122",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## List
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/contact/api#List](https://m3o.com/contact/api#List)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func ListContactsWithDefaultOffsetAndLimitDefaultLimitIs20() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.List(&contact.ListRequest{
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## List
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/contact/api#List](https://m3o.com/contact/api#List)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func ListContactsWithSpecificOffsetAndLimit() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.List(&contact.ListRequest{
|
|
||||||
Limit: 1,
|
|
||||||
Offset: 1,
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Create
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/contact/api#Create](https://m3o.com/contact/api#Create)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func CreateAcontact() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.Create(&contact.CreateRequest{
|
|
||||||
Addresses: []contact.Address{
|
|
||||||
contact.Address{
|
|
||||||
Label: "company address",
|
|
||||||
Location: "123 street address",
|
|
||||||
}},
|
|
||||||
Birthday: "1995-01-01",
|
|
||||||
Emails: []contact.Email{
|
|
||||||
contact.Email{
|
|
||||||
Address: "home@example.com",
|
|
||||||
Label: "home",
|
|
||||||
}},
|
|
||||||
Links: []contact.Link{
|
|
||||||
contact.Link{
|
|
||||||
Label: "blog",
|
|
||||||
Url: "https://blog.joe.me",
|
|
||||||
}},
|
|
||||||
Name: "joe",
|
|
||||||
Note: "this person is very important",
|
|
||||||
Phones: []contact.Phone{
|
|
||||||
contact.Phone{
|
|
||||||
Label: "home",
|
|
||||||
Number: "010-12345678",
|
|
||||||
}},
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Update
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/contact/api#Update](https://m3o.com/contact/api#Update)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func UpdateAcontact() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.Update(&contact.UpdateRequest{
|
|
||||||
Addresses: []contact.Address{
|
|
||||||
contact.Address{
|
|
||||||
Label: "company address",
|
|
||||||
Location: "123 street address",
|
|
||||||
}},
|
|
||||||
Birthday: "1995-01-01",
|
|
||||||
Emails: []contact.Email{
|
|
||||||
contact.Email{
|
|
||||||
Address: "home@example.com",
|
|
||||||
Label: "home",
|
|
||||||
}},
|
|
||||||
Id: "42e48a3c-6221-11ec-96d2-acde48001122",
|
|
||||||
Links: []contact.Link{
|
|
||||||
contact.Link{
|
|
||||||
Label: "blog",
|
|
||||||
Url: "https://blog.joe.me",
|
|
||||||
}},
|
|
||||||
Name: "joe",
|
|
||||||
Note: "this person is very important",
|
|
||||||
Phones: []contact.Phone{
|
|
||||||
contact.Phone{
|
|
||||||
Label: "home",
|
|
||||||
Number: "010-12345678",
|
|
||||||
}},
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Read
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/contact/api#Read](https://m3o.com/contact/api#Read)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func GetAcontact() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.Read(&contact.ReadRequest{
|
|
||||||
Id: "42e48a3c-6221-11ec-96d2-acde48001122",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func main() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.Create(&contact.CreateRequest{
|
|
||||||
Addresses: []contact.Address{
|
|
||||||
contact.Address{
|
|
||||||
Label: "company address",
|
|
||||||
Location: "123 street address",
|
|
||||||
}},
|
|
||||||
Birthday: "1995-01-01",
|
|
||||||
Emails: []contact.Email{
|
|
||||||
contact.Email{
|
|
||||||
Address: "home@example.com",
|
|
||||||
Label: "home",
|
|
||||||
}},
|
|
||||||
Links: []contact.Link{
|
|
||||||
contact.Link{
|
|
||||||
Label: "blog",
|
|
||||||
Url: "https://blog.joe.me",
|
|
||||||
}},
|
|
||||||
Name: "joe",
|
|
||||||
Note: "this person is very important",
|
|
||||||
Phones: []contact.Phone{
|
|
||||||
contact.Phone{
|
|
||||||
Label: "home",
|
|
||||||
Number: "010-12345678",
|
|
||||||
}},
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func main() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.Delete(&contact.DeleteRequest{
|
|
||||||
Id: "42e48a3c-6221-11ec-96d2-acde48001122",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func main() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.List(&contact.ListRequest{})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func main() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.List(&contact.ListRequest{
|
|
||||||
Limit: 1,
|
|
||||||
Offset: 1,
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func main() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.Read(&contact.ReadRequest{
|
|
||||||
Id: "42e48a3c-6221-11ec-96d2-acde48001122",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
//
|
|
||||||
func main() {
|
|
||||||
contactService := contact.NewContactService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := contactService.Update(&contact.UpdateRequest{
|
|
||||||
Addresses: []contact.Address{
|
|
||||||
contact.Address{
|
|
||||||
Label: "company address",
|
|
||||||
Location: "123 street address",
|
|
||||||
}},
|
|
||||||
Birthday: "1995-01-01",
|
|
||||||
Emails: []contact.Email{
|
|
||||||
contact.Email{
|
|
||||||
Address: "home@example.com",
|
|
||||||
Label: "home",
|
|
||||||
}},
|
|
||||||
Id: "42e48a3c-6221-11ec-96d2-acde48001122",
|
|
||||||
Links: []contact.Link{
|
|
||||||
contact.Link{
|
|
||||||
Label: "blog",
|
|
||||||
Url: "https://blog.joe.me",
|
|
||||||
}},
|
|
||||||
Name: "joe",
|
|
||||||
Note: "this person is very important",
|
|
||||||
Phones: []contact.Phone{
|
|
||||||
contact.Phone{
|
|
||||||
Label: "home",
|
|
||||||
Number: "010-12345678",
|
|
||||||
}},
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
# Crypto
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/crypto/api](https://m3o.com/crypto/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## Quote
|
|
||||||
|
|
||||||
Get the last quote for a given crypto ticker
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/crypto/api#Quote](https://m3o.com/crypto/api#Quote)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get the last quote for a given crypto ticker
|
|
||||||
func GetAcryptocurrencyQuote() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.Quote(&crypto.QuoteRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## History
|
|
||||||
|
|
||||||
Returns the history for the previous close
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/crypto/api#History](https://m3o.com/crypto/api#History)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Returns the history for the previous close
|
|
||||||
func GetPreviousClose() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.History(&crypto.HistoryRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## News
|
|
||||||
|
|
||||||
Get news related to a currency
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/crypto/api#News](https://m3o.com/crypto/api#News)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get news related to a currency
|
|
||||||
func GetCryptocurrencyNews() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.News(&crypto.NewsRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Price
|
|
||||||
|
|
||||||
Get the last price for a given crypto ticker
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/crypto/api#Price](https://m3o.com/crypto/api#Price)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get the last price for a given crypto ticker
|
|
||||||
func GetCryptocurrencyPrice() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.Price(&crypto.PriceRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Returns the history for the previous close
|
|
||||||
func GetPreviousClose() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.History(&crypto.HistoryRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Returns the history for the previous close
|
|
||||||
func main() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.History(&crypto.HistoryRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get news related to a currency
|
|
||||||
func GetCryptocurrencyNews() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.News(&crypto.NewsRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get news related to a currency
|
|
||||||
func main() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.News(&crypto.NewsRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get the last price for a given crypto ticker
|
|
||||||
func GetCryptocurrencyPrice() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.Price(&crypto.PriceRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get the last price for a given crypto ticker
|
|
||||||
func main() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.Price(&crypto.PriceRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get the last quote for a given crypto ticker
|
|
||||||
func GetAcryptocurrencyQuote() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.Quote(&crypto.QuoteRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get the last quote for a given crypto ticker
|
|
||||||
func main() {
|
|
||||||
cryptoService := crypto.NewCryptoService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := cryptoService.Quote(&crypto.QuoteRequest{
|
|
||||||
Symbol: "BTCUSD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
# Currency
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/currency/api](https://m3o.com/currency/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## Codes
|
|
||||||
|
|
||||||
Codes returns the supported currency codes for the API
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/currency/api#Codes](https://m3o.com/currency/api#Codes)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Codes returns the supported currency codes for the API
|
|
||||||
func GetSupportedCodes() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Codes(¤cy.CodesRequest{
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Rates
|
|
||||||
|
|
||||||
Rates returns the currency rates for a given code e.g USD
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/currency/api#Rates](https://m3o.com/currency/api#Rates)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Rates returns the currency rates for a given code e.g USD
|
|
||||||
func GetRatesForUsd() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Rates(¤cy.RatesRequest{
|
|
||||||
Code: "USD",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Convert
|
|
||||||
|
|
||||||
Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/currency/api#Convert](https://m3o.com/currency/api#Convert)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
||||||
func ConvertUsdToGbp() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Convert(¤cy.ConvertRequest{
|
|
||||||
From: "USD",
|
|
||||||
To: "GBP",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Convert
|
|
||||||
|
|
||||||
Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/currency/api#Convert](https://m3o.com/currency/api#Convert)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
||||||
func Convert10usdToGbp() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Convert(¤cy.ConvertRequest{
|
|
||||||
Amount: 10,
|
|
||||||
From: "USD",
|
|
||||||
To: "GBP",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## History
|
|
||||||
|
|
||||||
Returns the historic rates for a currency on a given date
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/currency/api#History](https://m3o.com/currency/api#History)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Returns the historic rates for a currency on a given date
|
|
||||||
func HistoricRatesForAcurrency() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.History(¤cy.HistoryRequest{
|
|
||||||
Code: "USD",
|
|
||||||
Date: "2021-05-30",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Codes returns the supported currency codes for the API
|
|
||||||
func GetSupportedCodes() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Codes(¤cy.CodesRequest{})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Codes returns the supported currency codes for the API
|
|
||||||
func main() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Codes(¤cy.CodesRequest{})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
||||||
func Convert10usdToGbp() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Convert(¤cy.ConvertRequest{
|
|
||||||
Amount: 10,
|
|
||||||
From: "USD",
|
|
||||||
To: "GBP",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
||||||
func main() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Convert(¤cy.ConvertRequest{
|
|
||||||
Amount: 10,
|
|
||||||
From: "USD",
|
|
||||||
To: "GBP",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
||||||
func ConvertUsdToGbp() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Convert(¤cy.ConvertRequest{
|
|
||||||
From: "USD",
|
|
||||||
To: "GBP",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
||||||
func main() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Convert(¤cy.ConvertRequest{
|
|
||||||
From: "USD",
|
|
||||||
To: "GBP",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Returns the historic rates for a currency on a given date
|
|
||||||
func HistoricRatesForAcurrency() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.History(¤cy.HistoryRequest{
|
|
||||||
Code: "USD",
|
|
||||||
Date: "2021-05-30",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Returns the historic rates for a currency on a given date
|
|
||||||
func main() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.History(¤cy.HistoryRequest{
|
|
||||||
Code: "USD",
|
|
||||||
Date: "2021-05-30",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Rates returns the currency rates for a given code e.g USD
|
|
||||||
func GetRatesForUsd() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Rates(¤cy.RatesRequest{
|
|
||||||
Code: "USD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/currency"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Rates returns the currency rates for a given code e.g USD
|
|
||||||
func main() {
|
|
||||||
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := currencyService.Rates(¤cy.RatesRequest{
|
|
||||||
Code: "USD",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,270 +0,0 @@
|
|||||||
# Db
|
|
||||||
|
|
||||||
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/db/api](https://m3o.com/db/api).
|
|
||||||
|
|
||||||
Endpoints:
|
|
||||||
|
|
||||||
## RenameTable
|
|
||||||
|
|
||||||
Rename a table
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/db/api#RenameTable](https://m3o.com/db/api#RenameTable)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Rename a table
|
|
||||||
func RenameTable() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.RenameTable(&db.RenameTableRequest{
|
|
||||||
From: "examples2",
|
|
||||||
To: "examples3",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Delete
|
|
||||||
|
|
||||||
Delete a record in the database by id.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/db/api#Delete](https://m3o.com/db/api#Delete)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete a record in the database by id.
|
|
||||||
func DeleteArecord() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Delete(&db.DeleteRequest{
|
|
||||||
Id: "1",
|
|
||||||
Table: "example",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## ListTables
|
|
||||||
|
|
||||||
List tables in the DB
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/db/api#ListTables](https://m3o.com/db/api#ListTables)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// List tables in the DB
|
|
||||||
func ListTables() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.ListTables(&db.ListTablesRequest{
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Read
|
|
||||||
|
|
||||||
Read data from a table. Lookup can be by ID or via querying any field in the record.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/db/api#Read](https://m3o.com/db/api#Read)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Read data from a table. Lookup can be by ID or via querying any field in the record.
|
|
||||||
func ReadRecords() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Read(&db.ReadRequest{
|
|
||||||
Query: "age == 43",
|
|
||||||
Table: "example",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Truncate
|
|
||||||
|
|
||||||
Truncate the records in a table
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/db/api#Truncate](https://m3o.com/db/api#Truncate)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Truncate the records in a table
|
|
||||||
func TruncateTable() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Truncate(&db.TruncateRequest{
|
|
||||||
Table: "example",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## DropTable
|
|
||||||
|
|
||||||
Drop a table in the DB
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/db/api#DropTable](https://m3o.com/db/api#DropTable)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Drop a table in the DB
|
|
||||||
func DropTable() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.DropTable(&db.DropTableRequest{
|
|
||||||
Table: "example",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Count
|
|
||||||
|
|
||||||
Count records in a table
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/db/api#Count](https://m3o.com/db/api#Count)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Count records in a table
|
|
||||||
func CountEntriesInAtable() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Count(&db.CountRequest{
|
|
||||||
Table: "example",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Create
|
|
||||||
|
|
||||||
Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/db/api#Create](https://m3o.com/db/api#Create)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
|
||||||
func CreateArecord() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Create(&db.CreateRequest{
|
|
||||||
Record: map[string]interface{}{
|
|
||||||
"id": "1",
|
|
||||||
"name": "Jane",
|
|
||||||
"age": 42,
|
|
||||||
"isActive": true,
|
|
||||||
},
|
|
||||||
Table: "example",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## Update
|
|
||||||
|
|
||||||
Update a record in the database. Include an "id" in the record to update.
|
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/db/api#Update](https://m3o.com/db/api#Update)
|
|
||||||
|
|
||||||
```go
|
|
||||||
package example
|
|
||||||
|
|
||||||
import(
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Update a record in the database. Include an "id" in the record to update.
|
|
||||||
func UpdateArecord() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Update(&db.UpdateRequest{
|
|
||||||
Record: map[string]interface{}{
|
|
||||||
"id": "1",
|
|
||||||
"age": 43,
|
|
||||||
},
|
|
||||||
Table: "example",
|
|
||||||
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Count records in a table
|
|
||||||
func CountEntriesInAtable() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Count(&db.CountRequest{
|
|
||||||
Table: "users",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Count records in a table
|
|
||||||
func main() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Count(&db.CountRequest{
|
|
||||||
Table: "example",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
|
||||||
func CreateArecord() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Create(&db.CreateRequest{
|
|
||||||
Record: map[string]interface{}{
|
|
||||||
"id": "1",
|
|
||||||
"name": "Jane",
|
|
||||||
"age": 42,
|
|
||||||
"isActive": true,
|
|
||||||
},
|
|
||||||
Table: "users",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
|
||||||
func main() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Create(&db.CreateRequest{
|
|
||||||
Record: map[string]interface{}{
|
|
||||||
"id": "1",
|
|
||||||
"name": "Jane",
|
|
||||||
"age": 42,
|
|
||||||
"isActive": true,
|
|
||||||
},
|
|
||||||
Table: "example",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete a record in the database by id.
|
|
||||||
func DeleteArecord() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Delete(&db.DeleteRequest{
|
|
||||||
Id: "1",
|
|
||||||
Table: "users",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete a record in the database by id.
|
|
||||||
func main() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Delete(&db.DeleteRequest{
|
|
||||||
Id: "1",
|
|
||||||
Table: "example",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Drop a table in the DB
|
|
||||||
func main() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.DropTable(&db.DropTableRequest{
|
|
||||||
Table: "example",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// List tables in the DB
|
|
||||||
func main() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.ListTables(&db.ListTablesRequest{})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.m3o.com/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Read data from a table. Lookup can be by ID or via querying any field in the record.
|
|
||||||
func ReadRecords() {
|
|
||||||
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
||||||
rsp, err := dbService.Read(&db.ReadRequest{
|
|
||||||
Query: "age == 43",
|
|
||||||
Table: "users",
|
|
||||||
})
|
|
||||||
fmt.Println(rsp, err)
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user