mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-24 15:35:30 +00:00
Compare commits
75 Commits
addservice
...
ci
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18df6dada9 | ||
|
|
b0f9eae01a | ||
|
|
913e2d609a | ||
|
|
ec70bb0b96 | ||
|
|
0e5e506abb | ||
|
|
96b0791847 | ||
|
|
15117f4033 | ||
|
|
716231b211 | ||
|
|
abbc8bcd49 | ||
|
|
c5f35e9f42 | ||
|
|
1b52b0f771 | ||
|
|
6533fdf6ff | ||
|
|
476fc61f51 | ||
|
|
fa2e8a5283 | ||
|
|
a8b7e20a0c | ||
|
|
d38b38c742 | ||
|
|
47e7a6709f | ||
|
|
68b5269093 | ||
|
|
4707018011 | ||
|
|
f3da9bd908 | ||
|
|
2ccc1a4d17 | ||
|
|
eff35e79ef | ||
|
|
fe077602a7 | ||
|
|
e2913e9e7c | ||
|
|
0561a7f7c2 | ||
|
|
21ded67c07 | ||
|
|
b3f128386d | ||
|
|
97f56e72a2 | ||
|
|
c64b4b029f | ||
|
|
5c6ed49281 | ||
|
|
6411450031 | ||
|
|
1c389d4cca | ||
|
|
0805168f1d | ||
|
|
429a6ad180 | ||
|
|
218188cbcf | ||
|
|
168985fe21 | ||
|
|
6d4b56721d | ||
|
|
9482db748c | ||
|
|
a3b4eba5f1 | ||
|
|
c84accfb12 | ||
|
|
a4c61983ce | ||
|
|
814f4826d6 | ||
|
|
a142615a6b | ||
|
|
7b95e8f58f | ||
|
|
cdd1eea406 | ||
|
|
8604d436eb | ||
|
|
eb73d115f2 | ||
|
|
4e64b77e47 | ||
|
|
8e9779a8cb | ||
|
|
c5c2867dc3 | ||
|
|
0a3298c33b | ||
|
|
5c34812294 | ||
|
|
2576812b54 | ||
|
|
8fc6fd6913 | ||
|
|
f3f53f865a | ||
|
|
1682d4075e | ||
|
|
c2ee05e2eb | ||
|
|
268689a87d | ||
|
|
e8c2e112f5 | ||
|
|
f5260050e4 | ||
|
|
f33dc1e44c | ||
|
|
ae73a4aca1 | ||
|
|
87f310675d | ||
|
|
6b328d406c | ||
|
|
aba344cf69 | ||
|
|
fced949d94 | ||
|
|
ec8910b174 | ||
|
|
f8f41e7434 | ||
|
|
55b73f2fc7 | ||
|
|
f2f62ad942 | ||
|
|
101c159dcf | ||
|
|
a4f018a78d | ||
|
|
726d1ccef6 | ||
|
|
ba48658a46 | ||
|
|
8b37b56cb3 |
26
.github/workflows/generate.yml
vendored
Normal file
26
.github/workflows/generate.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
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: |
|
||||||
|
cd examples/helloworld/call/callTheHelloworldService
|
||||||
|
go run main.go
|
||||||
35
README.md
35
README.md
@@ -4,6 +4,35 @@ This is the Go client to access APIs on the M3O Platform
|
|||||||
|
|
||||||
## Usage
|
## 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
|
||||||
|
|
||||||
@@ -11,7 +40,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
@@ -49,7 +78,7 @@ func main() {
|
|||||||
|
|
||||||
## Streaming
|
## Streaming
|
||||||
|
|
||||||
The client supports streaming
|
The client supports streaming but is not yet code generated. Use the following for streaming endpoints.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -57,7 +86,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package address
|
package address
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewAddressService(token string) *AddressService {
|
func NewAddressService(token string) *AddressService {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package answer
|
package answer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewAnswerService(token string) *AnswerService {
|
func NewAnswerService(token string) *AnswerService {
|
||||||
14
service/cache/cache.go → cache/cache.go
vendored
14
service/cache/cache.go → cache/cache.go
vendored
@@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCacheService(token string) *CacheService {
|
func NewCacheService(token string) *CacheService {
|
||||||
@@ -50,14 +50,14 @@ type DecrementRequest struct {
|
|||||||
// The key to decrement
|
// The key to decrement
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
// The amount to decrement the value by
|
// The amount to decrement the value by
|
||||||
Value int64 `json:"value"`
|
Value int64 `json:"value,string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DecrementResponse struct {
|
type DecrementResponse struct {
|
||||||
// The key decremented
|
// The key decremented
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
// The new value
|
// The new value
|
||||||
Value int64 `json:"value"`
|
Value int64 `json:"value,string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteRequest struct {
|
type DeleteRequest struct {
|
||||||
@@ -79,7 +79,7 @@ type GetResponse struct {
|
|||||||
// The key
|
// The key
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
// Time to live in seconds
|
// Time to live in seconds
|
||||||
Ttl int64 `json:"ttl"`
|
Ttl int64 `json:"ttl,string"`
|
||||||
// The value
|
// The value
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
}
|
}
|
||||||
@@ -88,21 +88,21 @@ type IncrementRequest struct {
|
|||||||
// The key to increment
|
// The key to increment
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
// The amount to increment the value by
|
// The amount to increment the value by
|
||||||
Value int64 `json:"value"`
|
Value int64 `json:"value,string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IncrementResponse struct {
|
type IncrementResponse struct {
|
||||||
// The key incremented
|
// The key incremented
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
// The new value
|
// The new value
|
||||||
Value int64 `json:"value"`
|
Value int64 `json:"value,string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetRequest struct {
|
type SetRequest struct {
|
||||||
// The key to update
|
// The key to update
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
// Time to live in seconds
|
// Time to live in seconds
|
||||||
Ttl int64 `json:"ttl"`
|
Ttl int64 `json:"ttl,string"`
|
||||||
// The value to set
|
// The value to set
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
}
|
}
|
||||||
201
cmd/m3o-go-url/LICENSE
Normal file
201
cmd/m3o-go-url/LICENSE
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
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.
|
||||||
134
cmd/m3o-go-url/README.md
Normal file
134
cmd/m3o-go-url/README.md
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
# 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>
|
||||||
10
cmd/m3o-go-url/go.mod
Normal file
10
cmd/m3o-go-url/go.mod
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
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
|
||||||
|
)
|
||||||
13
cmd/m3o-go-url/go.sum
Normal file
13
cmd/m3o-go-url/go.sum
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
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=
|
||||||
225
cmd/m3o-go-url/handler.go
Normal file
225
cmd/m3o-go-url/handler.go
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
// 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
|
||||||
|
}
|
||||||
315
cmd/m3o-go-url/handler_test.go
Normal file
315
cmd/m3o-go-url/handler_test.go
Normal file
@@ -0,0 +1,315 @@
|
|||||||
|
// 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
55
cmd/m3o-go-url/main.go
Normal file
55
cmd/m3o-go-url/main.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
// 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
|
||||||
|
}
|
||||||
5
cmd/m3o-go-url/vanity.yaml
Normal file
5
cmd/m3o-go-url/vanity.yaml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
host: go.m3o.com
|
||||||
|
|
||||||
|
paths:
|
||||||
|
/:
|
||||||
|
repo: https://github.com/m3o/m3o-go
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package crypto
|
package crypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCryptoService(token string) *CryptoService {
|
func NewCryptoService(token string) *CryptoService {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package currency
|
package currency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCurrencyService(token string) *CurrencyService {
|
func NewCurrencyService(token string) *CurrencyService {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewDbService(token string) *DbService {
|
func NewDbService(token string) *DbService {
|
||||||
@@ -16,6 +16,12 @@ type DbService struct {
|
|||||||
client *client.Client
|
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.
|
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
||||||
func (t *DbService) Create(request *CreateRequest) (*CreateResponse, error) {
|
func (t *DbService) Create(request *CreateRequest) (*CreateResponse, error) {
|
||||||
rsp := &CreateResponse{}
|
rsp := &CreateResponse{}
|
||||||
@@ -46,6 +52,16 @@ func (t *DbService) Update(request *UpdateRequest) (*UpdateResponse, error) {
|
|||||||
return rsp, t.client.Call("db", "Update", request, rsp)
|
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 {
|
type CreateRequest struct {
|
||||||
// JSON encoded record or records (can be array or object)
|
// JSON encoded record or records (can be array or object)
|
||||||
Record map[string]interface{} `json:"record"`
|
Record map[string]interface{} `json:"record"`
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package email
|
package email
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewEmailService(token string) *EmailService {
|
func NewEmailService(token string) *EmailService {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package emoji
|
package emoji
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/m3o/m3o-go/client"
|
"go.m3o.com/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewEmojiService(token string) *EmojiService {
|
func NewEmojiService(token string) *EmojiService {
|
||||||
240
evchargers/evchargers.go
Executable file
240
evchargers/evchargers.go
Executable file
@@ -0,0 +1,240 @@
|
|||||||
|
package evchargers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.m3o.com/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
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:"accessComments"`
|
||||||
|
AddressLine1 string `json:"addressLine1"`
|
||||||
|
AddressLine2 string `json:"addressLine2"`
|
||||||
|
Country *Country `json:"country"`
|
||||||
|
CountryId string `json:"countryId"`
|
||||||
|
LatLng string `json:"latLng"`
|
||||||
|
Location *Coordinates `json:"location"`
|
||||||
|
Postcode string `json:"postcode"`
|
||||||
|
StateOrProvince string `json:"stateOrProvince"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Town string `json:"town"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BoundingBox struct {
|
||||||
|
BottomLeft *Coordinates `json:"bottomLeft"`
|
||||||
|
TopRight *Coordinates `json:"topRight"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChargerType struct {
|
||||||
|
Comments string `json:"comments"`
|
||||||
|
Id string `json:"id"`
|
||||||
|
// Is this 40KW+
|
||||||
|
IsFastChargeCapable bool `json:"isFastChargeCapable"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckinStatusType struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
IsAutomated bool `json:"isAutomated"`
|
||||||
|
IsPositive bool `json:"isPositive"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Connection struct {
|
||||||
|
// The amps offered
|
||||||
|
Amps float64 `json:"amps"`
|
||||||
|
ConnectionType *ConnectionType `json:"connectionType"`
|
||||||
|
// The ID of the connection type
|
||||||
|
ConnectionTypeId string `json:"connectionTypeId"`
|
||||||
|
// The current
|
||||||
|
Current string `json:"current"`
|
||||||
|
Level *ChargerType `json:"level"`
|
||||||
|
// The level of charging power available
|
||||||
|
LevelId string `json:"levelId"`
|
||||||
|
// 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:"formalName"`
|
||||||
|
Id string `json:"id"`
|
||||||
|
IsDiscontinued bool `json:"isDiscontinued"`
|
||||||
|
IsObsolete bool `json:"isObsolete"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Coordinates struct {
|
||||||
|
Latitude float64 `json:"latitude"`
|
||||||
|
Longitude float64 `json:"longitude"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Country struct {
|
||||||
|
ContinentCode string `json:"continentCode"`
|
||||||
|
Id string `json:"id"`
|
||||||
|
IsoCode string `json:"isoCode"`
|
||||||
|
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:"dataProviderStatusType"`
|
||||||
|
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:"isProviderEnabled"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Operator struct {
|
||||||
|
Comments string `json:"comments"`
|
||||||
|
ContactEmail string `json:"contactEmail"`
|
||||||
|
FaultReportEmail string `json:"faultReportEmail"`
|
||||||
|
Id string `json:"id"`
|
||||||
|
// Is this operator a private individual vs a company
|
||||||
|
IsPrivateIndividual bool `json:"isPrivateIndividual"`
|
||||||
|
PhonePrimary string `json:"phonePrimary"`
|
||||||
|
PhoneSecondary string `json:"phoneSecondary"`
|
||||||
|
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:"dataProviderId"`
|
||||||
|
// The ID of the charger
|
||||||
|
Id string `json:"id"`
|
||||||
|
// The number of charging points
|
||||||
|
NumPoints int64 `json:"numPoints,string"`
|
||||||
|
// The operator
|
||||||
|
Operator *Operator `json:"operator"`
|
||||||
|
// The ID of the operator of the charger
|
||||||
|
OperatorId string `json:"operatorId"`
|
||||||
|
// The type of usage
|
||||||
|
UsageType *UsageType `json:"usageType"`
|
||||||
|
// The type of usage for this charger point (is it public, membership required, etc)
|
||||||
|
UsageTypeId string `json:"usageTypeId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReferenceDataRequest struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReferenceDataResponse struct {
|
||||||
|
// The types of charger
|
||||||
|
ChargerTypes *ChargerType `json:"chargerTypes"`
|
||||||
|
// The types of checkin status
|
||||||
|
CheckinStatusTypes *CheckinStatusType `json:"checkinStatusTypes"`
|
||||||
|
// The types of connection
|
||||||
|
ConnectionTypes *ConnectionType `json:"connectionTypes"`
|
||||||
|
// The countries
|
||||||
|
Countries []Country `json:"countries"`
|
||||||
|
// The types of current
|
||||||
|
CurrentTypes *CurrentType `json:"currentTypes"`
|
||||||
|
// The providers of the charger data
|
||||||
|
DataProviders *DataProvider `json:"dataProviders"`
|
||||||
|
// The companies operating the chargers
|
||||||
|
Operators []Operator `json:"operators"`
|
||||||
|
// The status of the charger
|
||||||
|
StatusTypes *StatusType `json:"statusTypes"`
|
||||||
|
// The status of a submission
|
||||||
|
SubmissionStatusTypes *SubmissionStatusType `json:"submissionStatusTypes"`
|
||||||
|
// The different types of usage
|
||||||
|
UsageTypes *UsageType `json:"usageTypes"`
|
||||||
|
// The types of user comment
|
||||||
|
UserCommentTypes *UserCommentType `json:"userCommentTypes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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:"connectionTypes"`
|
||||||
|
// Country ID
|
||||||
|
CountryId string `json:"countryId"`
|
||||||
|
// 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:"maxResults,string"`
|
||||||
|
// Minimum power in KW. Note: data not available for many chargers
|
||||||
|
MinPower int64 `json:"minPower,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:"usageTypes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchResponse struct {
|
||||||
|
Pois []Poi `json:"pois"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type StatusType struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
IsOperational bool `json:"isOperational"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubmissionStatusType struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
IsLive bool `json:"isLive"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UsageType struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
IsAccessKeyRequired bool `json:"isAccessKeyRequired"`
|
||||||
|
IsMembershipRequired bool `json:"isMembershipRequired"`
|
||||||
|
IsPayAtLocation bool `json:"isPayAtLocation"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserCommentType struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
53
event/event.go
Executable file
53
event/event.go
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
package event
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.m3o.com/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewEventService(token string) *EventService {
|
||||||
|
return &EventService{
|
||||||
|
client: client.NewClient(&client.Options{
|
||||||
|
Token: token,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type EventService struct {
|
||||||
|
client *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish a message to the event stream.
|
||||||
|
func (t *EventService) Publish(request *PublishRequest) (*PublishResponse, error) {
|
||||||
|
rsp := &PublishResponse{}
|
||||||
|
return rsp, t.client.Call("event", "Publish", request, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subscribe to messages for a given topic.
|
||||||
|
func (t *EventService) Subscribe(request *SubscribeRequest) (*SubscribeResponse, error) {
|
||||||
|
rsp := &SubscribeResponse{}
|
||||||
|
return rsp, t.client.Call("event", "Subscribe", request, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PublishRequest struct {
|
||||||
|
// The json message to publish
|
||||||
|
Message map[string]interface{} `json:"message"`
|
||||||
|
// The topic to publish to
|
||||||
|
Topic string `json:"topic"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PublishResponse struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscribeRequest struct {
|
||||||
|
// Optional group for the subscription
|
||||||
|
Group string `json:"group"`
|
||||||
|
// The topic to subscribe to
|
||||||
|
Topic string `json:"topic"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscribeResponse struct {
|
||||||
|
// The next json message on the topic
|
||||||
|
Message map[string]interface{} `json:"message"`
|
||||||
|
// The topic subscribed to
|
||||||
|
Topic string `json:"topic"`
|
||||||
|
}
|
||||||
33
examples/address/README.md
Executable file
33
examples/address/README.md
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
# 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)
|
||||||
|
}
|
||||||
|
```
|
||||||
17
examples/address/lookupPostcode/lookupPostcode.go
Executable file
17
examples/address/lookupPostcode/lookupPostcode.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
33
examples/answer/README.md
Executable file
33
examples/answer/README.md
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
# 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)
|
||||||
|
}
|
||||||
|
```
|
||||||
17
examples/answer/question/askAQuestion.go
Executable file
17
examples/answer/question/askAQuestion.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
144
examples/cache/README.md
vendored
Executable file
144
examples/cache/README.md
vendored
Executable file
@@ -0,0 +1,144 @@
|
|||||||
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
|
[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)
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
[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)
|
||||||
|
func DecrementAvalue() {
|
||||||
|
cacheService := cache.NewCacheService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := cacheService.Decrement(&cache.DecrementRequest{
|
||||||
|
Key: "counter",
|
||||||
|
Value: 2,
|
||||||
|
|
||||||
|
})
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
[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
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
[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
|
||||||
|
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
Executable file
18
examples/cache/decrement/decrementAValue.go
vendored
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/cache"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Decrement a value (if it's a number)
|
||||||
|
func DecrementAvalue() {
|
||||||
|
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
Executable file
17
examples/cache/delete/deleteAValue.go
vendored
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/cache"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete a value from the cache
|
||||||
|
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/get/getAValue.go
vendored
Executable file
17
examples/cache/get/getAValue.go
vendored
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/cache"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get an item from the cache by key
|
||||||
|
func GetAvalue() {
|
||||||
|
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
Executable file
18
examples/cache/increment/incrementAValue.go
vendored
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/cache"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Increment a value (if it's a number)
|
||||||
|
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/set/setAValue.go
vendored
Executable file
18
examples/cache/set/setAValue.go
vendored
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
114
examples/crypto/README.md
Executable file
114
examples/crypto/README.md
Executable file
@@ -0,0 +1,114 @@
|
|||||||
|
# Crypto
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Crypto/api](https://m3o.com/Crypto/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## 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)
|
||||||
|
}
|
||||||
|
```
|
||||||
17
examples/crypto/history/getPreviousClose.go
Executable file
17
examples/crypto/history/getPreviousClose.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
17
examples/crypto/news/getCryptocurrencyNews.go
Executable file
17
examples/crypto/news/getCryptocurrencyNews.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
17
examples/crypto/price/getCryptocurrencyPrice.go
Executable file
17
examples/crypto/price/getCryptocurrencyPrice.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
17
examples/crypto/quote/getACryptocurrencyQuote.go
Executable file
17
examples/crypto/quote/getACryptocurrencyQuote.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
144
examples/currency/README.md
Executable file
144
examples/currency/README.md
Executable file
@@ -0,0 +1,144 @@
|
|||||||
|
# Currency
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Currency/api](https://m3o.com/Currency/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## 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)
|
||||||
|
}
|
||||||
|
```
|
||||||
15
examples/currency/codes/getSupportedCodes.go
Executable file
15
examples/currency/codes/getSupportedCodes.go
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
19
examples/currency/convert/convert10UsdToGbp.go
Executable file
19
examples/currency/convert/convert10UsdToGbp.go
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
18
examples/currency/convert/convertUsdToGbp.go
Executable file
18
examples/currency/convert/convertUsdToGbp.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
18
examples/currency/history/historicRatesForACurrency.go
Executable file
18
examples/currency/history/historicRatesForACurrency.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
17
examples/currency/rates/getRatesForUsd.go
Executable file
17
examples/currency/rates/getRatesForUsd.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
180
examples/db/README.md
Executable file
180
examples/db/README.md
Executable file
@@ -0,0 +1,180 @@
|
|||||||
|
# Db
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Db/api](https://m3o.com/Db/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## 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: "users",
|
||||||
|
|
||||||
|
})
|
||||||
|
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: "users",
|
||||||
|
|
||||||
|
})
|
||||||
|
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{}{
|
||||||
|
"name": "Jane",
|
||||||
|
"age": 42,
|
||||||
|
"isActive": true,
|
||||||
|
"id": "1",
|
||||||
|
},
|
||||||
|
Table: "users",
|
||||||
|
|
||||||
|
})
|
||||||
|
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: "users",
|
||||||
|
|
||||||
|
})
|
||||||
|
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: "users",
|
||||||
|
|
||||||
|
})
|
||||||
|
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: "users",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
17
examples/db/count/countEntriesInATable.go
Executable file
17
examples/db/count/countEntriesInATable.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
23
examples/db/create/createARecord.go
Executable file
23
examples/db/create/createARecord.go
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
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{}{
|
||||||
|
"isActive": true,
|
||||||
|
"id": "1",
|
||||||
|
"name": "Jane",
|
||||||
|
"age": 42,
|
||||||
|
},
|
||||||
|
Table: "users",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
18
examples/db/delete/deleteARecord.go
Executable file
18
examples/db/delete/deleteARecord.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
18
examples/db/read/readRecords.go
Executable file
18
examples/db/read/readRecords.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
17
examples/db/truncate/truncateTable.go
Executable file
17
examples/db/truncate/truncateTable.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
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: "users",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
21
examples/db/update/updateARecord.go
Executable file
21
examples/db/update/updateARecord.go
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
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{}{
|
||||||
|
"age": 43,
|
||||||
|
"id": "1",
|
||||||
|
},
|
||||||
|
Table: "users",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
37
examples/email/README.md
Executable file
37
examples/email/README.md
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
# Email
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Email/api](https://m3o.com/Email/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Send
|
||||||
|
|
||||||
|
Send an email by passing in from, to, subject, and a text or html body
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/email/api#Send](https://m3o.com/email/api#Send)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/email"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send an email by passing in from, to, subject, and a text or html body
|
||||||
|
func SendEmail() {
|
||||||
|
emailService := email.NewEmailService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emailService.Send(&email.SendRequest{
|
||||||
|
From: "Awesome Dot Com",
|
||||||
|
Subject: "Email verification",
|
||||||
|
TextBody: `Hi there,
|
||||||
|
|
||||||
|
Please verify your email by clicking this link: $micro_verification_link`,
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
21
examples/email/send/sendEmail.go
Executable file
21
examples/email/send/sendEmail.go
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/email"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send an email by passing in from, to, subject, and a text or html body
|
||||||
|
func SendEmail() {
|
||||||
|
emailService := email.NewEmailService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emailService.Send(&email.SendRequest{
|
||||||
|
From: "Awesome Dot Com",
|
||||||
|
Subject: "Email verification",
|
||||||
|
TextBody: `Hi there,
|
||||||
|
|
||||||
|
Please verify your email by clicking this link: $micro_verification_link`,
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
117
examples/emoji/README.md
Executable file
117
examples/emoji/README.md
Executable file
@@ -0,0 +1,117 @@
|
|||||||
|
# Emoji
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Emoji/api](https://m3o.com/Emoji/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Find
|
||||||
|
|
||||||
|
Find an emoji by its alias e.g :beer:
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/emoji/api#Find](https://m3o.com/emoji/api#Find)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/emoji"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Find an emoji by its alias e.g :beer:
|
||||||
|
func FindEmoji() {
|
||||||
|
emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emojiService.Find(&emoji.FindRequest{
|
||||||
|
Alias: ":beer:",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Flag
|
||||||
|
|
||||||
|
Get the flag for a country. Requires country code e.g GB for great britain
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/emoji/api#Flag](https://m3o.com/emoji/api#Flag)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/emoji"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the flag for a country. Requires country code e.g GB for great britain
|
||||||
|
func GetFlagByCountryCode() {
|
||||||
|
emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emojiService.Flag(&emoji.FlagRequest{
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Print
|
||||||
|
|
||||||
|
Print text and renders the emojis with aliases e.g
|
||||||
|
let's grab a :beer: becomes let's grab a 🍺
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/emoji/api#Print](https://m3o.com/emoji/api#Print)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/emoji"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Print text and renders the emojis with aliases e.g
|
||||||
|
// let's grab a :beer: becomes let's grab a 🍺
|
||||||
|
func PrintTextIncludingEmoji() {
|
||||||
|
emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emojiService.Print(&emoji.PrintRequest{
|
||||||
|
Text: "let's grab a :beer:",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Send
|
||||||
|
|
||||||
|
Send an emoji to anyone via SMS. Messages are sent in the form '<message> Sent from <from>'
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/emoji/api#Send](https://m3o.com/emoji/api#Send)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/emoji"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send an emoji to anyone via SMS. Messages are sent in the form '<message> Sent from <from>'
|
||||||
|
func SendAtextContainingAnEmojiToAnyoneViaSms() {
|
||||||
|
emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emojiService.Send(&emoji.SendRequest{
|
||||||
|
From: "Alice",
|
||||||
|
Message: "let's grab a :beer:",
|
||||||
|
To: "+44782669123",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
17
examples/emoji/find/findEmoji.go
Executable file
17
examples/emoji/find/findEmoji.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/emoji"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Find an emoji by its alias e.g :beer:
|
||||||
|
func FindEmoji() {
|
||||||
|
emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emojiService.Find(&emoji.FindRequest{
|
||||||
|
Alias: ":beer:",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
15
examples/emoji/flag/getFlagByCountryCode.go
Executable file
15
examples/emoji/flag/getFlagByCountryCode.go
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/emoji"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the flag for a country. Requires country code e.g GB for great britain
|
||||||
|
func GetFlagByCountryCode() {
|
||||||
|
emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emojiService.Flag(&emoji.FlagRequest{})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
18
examples/emoji/print/printTextIncludingEmoji.go
Executable file
18
examples/emoji/print/printTextIncludingEmoji.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/emoji"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Print text and renders the emojis with aliases e.g
|
||||||
|
// let's grab a :beer: becomes let's grab a 🍺
|
||||||
|
func PrintTextIncludingEmoji() {
|
||||||
|
emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emojiService.Print(&emoji.PrintRequest{
|
||||||
|
Text: "let's grab a :beer:",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
19
examples/emoji/send/sendATextContainingAnEmojiToAnyoneViaSms.go
Executable file
19
examples/emoji/send/sendATextContainingAnEmojiToAnyoneViaSms.go
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/emoji"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send an emoji to anyone via SMS. Messages are sent in the form '<message> Sent from <from>'
|
||||||
|
func SendAtextContainingAnEmojiToAnyoneViaSms() {
|
||||||
|
emojiService := emoji.NewEmojiService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := emojiService.Send(&emoji.SendRequest{
|
||||||
|
From: "Alice",
|
||||||
|
Message: "let's grab a :beer:",
|
||||||
|
To: "+44782669123",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
123
examples/evchargers/README.md
Executable file
123
examples/evchargers/README.md
Executable file
@@ -0,0 +1,123 @@
|
|||||||
|
# Evchargers
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Evchargers/api](https://m3o.com/Evchargers/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Search
|
||||||
|
|
||||||
|
Search by giving a coordinate and a max distance, or bounding box and optional filters
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/evchargers/api#Search](https://m3o.com/evchargers/api#Search)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/evchargers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search by giving a coordinate and a max distance, or bounding box and optional filters
|
||||||
|
func SearchByLocation() {
|
||||||
|
evchargersService := evchargers.NewEvchargersService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := evchargersService.Search(&evchargers.SearchRequest{
|
||||||
|
Distance: 2000,
|
||||||
|
Location: &evchargers.Coordinates{
|
||||||
|
Latitude: 51.53336351319885,
|
||||||
|
Longitude: -0.0252,
|
||||||
|
},
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Search
|
||||||
|
|
||||||
|
Search by giving a coordinate and a max distance, or bounding box and optional filters
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/evchargers/api#Search](https://m3o.com/evchargers/api#Search)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/evchargers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search by giving a coordinate and a max distance, or bounding box and optional filters
|
||||||
|
func SearchByBoundingBox() {
|
||||||
|
evchargersService := evchargers.NewEvchargersService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := evchargersService.Search(&evchargers.SearchRequest{
|
||||||
|
Box: &evchargers.BoundingBox{
|
||||||
|
},
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Search
|
||||||
|
|
||||||
|
Search by giving a coordinate and a max distance, or bounding box and optional filters
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/evchargers/api#Search](https://m3o.com/evchargers/api#Search)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/evchargers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search by giving a coordinate and a max distance, or bounding box and optional filters
|
||||||
|
func SearchWithFiltersFastChargersOnly() {
|
||||||
|
evchargersService := evchargers.NewEvchargersService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := evchargersService.Search(&evchargers.SearchRequest{
|
||||||
|
Distance: 2000,
|
||||||
|
Levels: []string{"3"},
|
||||||
|
Location: &evchargers.Coordinates{
|
||||||
|
Latitude: 51.53336351319885,
|
||||||
|
Longitude: -0.0252,
|
||||||
|
},
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## ReferenceData
|
||||||
|
|
||||||
|
Retrieve reference data as used by this API and in conjunction with the Search endpoint
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/evchargers/api#ReferenceData](https://m3o.com/evchargers/api#ReferenceData)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/evchargers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Retrieve reference data as used by this API and in conjunction with the Search endpoint
|
||||||
|
func GetReferenceData() {
|
||||||
|
evchargersService := evchargers.NewEvchargersService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := evchargersService.ReferenceData(&evchargers.ReferenceDataRequest{
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
15
examples/evchargers/referenceData/getReferenceData.go
Executable file
15
examples/evchargers/referenceData/getReferenceData.go
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/evchargers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Retrieve reference data as used by this API and in conjunction with the Search endpoint
|
||||||
|
func GetReferenceData() {
|
||||||
|
evchargersService := evchargers.NewEvchargersService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := evchargersService.ReferenceData(&evchargers.ReferenceDataRequest{})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/evchargers/search/searchByBoundingBox.go
Executable file
17
examples/evchargers/search/searchByBoundingBox.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/evchargers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search by giving a coordinate and a max distance, or bounding box and optional filters
|
||||||
|
func SearchByBoundingBox() {
|
||||||
|
evchargersService := evchargers.NewEvchargersService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := evchargersService.Search(&evchargers.SearchRequest{
|
||||||
|
Box: &evchargers.BoundingBox{},
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
21
examples/evchargers/search/searchByLocation.go
Executable file
21
examples/evchargers/search/searchByLocation.go
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/evchargers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search by giving a coordinate and a max distance, or bounding box and optional filters
|
||||||
|
func SearchByLocation() {
|
||||||
|
evchargersService := evchargers.NewEvchargersService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := evchargersService.Search(&evchargers.SearchRequest{
|
||||||
|
Distance: 2000,
|
||||||
|
Location: &evchargers.Coordinates{
|
||||||
|
Latitude: 51.53336351319885,
|
||||||
|
Longitude: -0.0252,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
22
examples/evchargers/search/searchWithFiltersFastChargersOnly.go
Executable file
22
examples/evchargers/search/searchWithFiltersFastChargersOnly.go
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/evchargers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search by giving a coordinate and a max distance, or bounding box and optional filters
|
||||||
|
func SearchWithFiltersFastChargersOnly() {
|
||||||
|
evchargersService := evchargers.NewEvchargersService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := evchargersService.Search(&evchargers.SearchRequest{
|
||||||
|
Distance: 2000,
|
||||||
|
Levels: []string{"3"},
|
||||||
|
Location: &evchargers.Coordinates{
|
||||||
|
Latitude: 51.53336351319885,
|
||||||
|
Longitude: -0.0252,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
65
examples/event/README.md
Executable file
65
examples/event/README.md
Executable file
@@ -0,0 +1,65 @@
|
|||||||
|
# Event
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Event/api](https://m3o.com/Event/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Publish
|
||||||
|
|
||||||
|
Publish a message to the event stream.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/event/api#Publish](https://m3o.com/event/api#Publish)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Publish a message to the event stream.
|
||||||
|
func PublishAmessage() {
|
||||||
|
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := eventService.Publish(&event.PublishRequest{
|
||||||
|
Message: map[string]interface{}{
|
||||||
|
"user": "john",
|
||||||
|
"id": "1",
|
||||||
|
"type": "signup",
|
||||||
|
},
|
||||||
|
Topic: "user",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Subscribe
|
||||||
|
|
||||||
|
Subscribe to messages for a given topic.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/event/api#Subscribe](https://m3o.com/event/api#Subscribe)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Subscribe to messages for a given topic.
|
||||||
|
func SubscribeToAtopic() {
|
||||||
|
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := eventService.Subscribe(&event.SubscribeRequest{
|
||||||
|
Topic: "user",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
22
examples/event/publish/publishAMessage.go
Executable file
22
examples/event/publish/publishAMessage.go
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Publish a message to the event stream.
|
||||||
|
func PublishAmessage() {
|
||||||
|
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := eventService.Publish(&event.PublishRequest{
|
||||||
|
Message: map[string]interface{}{
|
||||||
|
"user": "john",
|
||||||
|
"id": "1",
|
||||||
|
"type": "signup",
|
||||||
|
},
|
||||||
|
Topic: "user",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/event/subscribe/subscribeToATopic.go
Executable file
17
examples/event/subscribe/subscribeToATopic.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Subscribe to messages for a given topic.
|
||||||
|
func SubscribeToAtopic() {
|
||||||
|
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := eventService.Subscribe(&event.SubscribeRequest{
|
||||||
|
Topic: "user",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
120
examples/file/README.md
Executable file
120
examples/file/README.md
Executable file
@@ -0,0 +1,120 @@
|
|||||||
|
# File
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/File/api](https://m3o.com/File/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Save
|
||||||
|
|
||||||
|
Save a file
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/file/api#Save](https://m3o.com/file/api#Save)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/file"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Save a file
|
||||||
|
func SaveFile() {
|
||||||
|
fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := fileService.Save(&file.SaveRequest{
|
||||||
|
File: &file.Record{
|
||||||
|
Content: "file content example",
|
||||||
|
Path: "/document/text-files/file.txt",
|
||||||
|
Project: "examples",
|
||||||
|
},
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## List
|
||||||
|
|
||||||
|
List files by their project and optionally a path.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/file/api#List](https://m3o.com/file/api#List)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/file"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List files by their project and optionally a path.
|
||||||
|
func ListFiles() {
|
||||||
|
fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := fileService.List(&file.ListRequest{
|
||||||
|
Project: "examples",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Delete
|
||||||
|
|
||||||
|
Delete a file by project name/path
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/file/api#Delete](https://m3o.com/file/api#Delete)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/file"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete a file by project name/path
|
||||||
|
func DeleteFile() {
|
||||||
|
fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := fileService.Delete(&file.DeleteRequest{
|
||||||
|
Path: "/document/text-files/file.txt",
|
||||||
|
Project: "examples",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Read
|
||||||
|
|
||||||
|
Read a file by path
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/file/api#Read](https://m3o.com/file/api#Read)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/file"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Read a file by path
|
||||||
|
func ReadFile() {
|
||||||
|
fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := fileService.Read(&file.ReadRequest{
|
||||||
|
Path: "/document/text-files/file.txt",
|
||||||
|
Project: "examples",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
18
examples/file/delete/deleteFile.go
Executable file
18
examples/file/delete/deleteFile.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/file"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete a file by project name/path
|
||||||
|
func DeleteFile() {
|
||||||
|
fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := fileService.Delete(&file.DeleteRequest{
|
||||||
|
Path: "/document/text-files/file.txt",
|
||||||
|
Project: "examples",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/file/list/listFiles.go
Executable file
17
examples/file/list/listFiles.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/file"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List files by their project and optionally a path.
|
||||||
|
func ListFiles() {
|
||||||
|
fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := fileService.List(&file.ListRequest{
|
||||||
|
Project: "examples",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
18
examples/file/read/readFile.go
Executable file
18
examples/file/read/readFile.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/file"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Read a file by path
|
||||||
|
func ReadFile() {
|
||||||
|
fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := fileService.Read(&file.ReadRequest{
|
||||||
|
Path: "/document/text-files/file.txt",
|
||||||
|
Project: "examples",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
21
examples/file/save/saveFile.go
Executable file
21
examples/file/save/saveFile.go
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/file"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Save a file
|
||||||
|
func SaveFile() {
|
||||||
|
fileService := file.NewFileService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := fileService.Save(&file.SaveRequest{
|
||||||
|
File: &file.Record{
|
||||||
|
Content: "file content example",
|
||||||
|
Path: "/document/text-files/file.txt",
|
||||||
|
Project: "examples",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
87
examples/forex/README.md
Executable file
87
examples/forex/README.md
Executable file
@@ -0,0 +1,87 @@
|
|||||||
|
# Forex
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Forex/api](https://m3o.com/Forex/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Quote
|
||||||
|
|
||||||
|
Get the latest quote for the forex
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/forex/api#Quote](https://m3o.com/forex/api#Quote)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/forex"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the latest quote for the forex
|
||||||
|
func GetAfxQuote() {
|
||||||
|
forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := forexService.Quote(&forex.QuoteRequest{
|
||||||
|
Symbol: "GBPUSD",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## History
|
||||||
|
|
||||||
|
Returns the data for the previous close
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/forex/api#History](https://m3o.com/forex/api#History)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/forex"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Returns the data for the previous close
|
||||||
|
func GetPreviousClose() {
|
||||||
|
forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := forexService.History(&forex.HistoryRequest{
|
||||||
|
Symbol: "GBPUSD",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Price
|
||||||
|
|
||||||
|
Get the latest price for a given forex ticker
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/forex/api#Price](https://m3o.com/forex/api#Price)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/forex"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the latest price for a given forex ticker
|
||||||
|
func GetAnFxPrice() {
|
||||||
|
forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := forexService.Price(&forex.PriceRequest{
|
||||||
|
Symbol: "GBPUSD",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
17
examples/forex/history/getPreviousClose.go
Executable file
17
examples/forex/history/getPreviousClose.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/forex"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Returns the data for the previous close
|
||||||
|
func GetPreviousClose() {
|
||||||
|
forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := forexService.History(&forex.HistoryRequest{
|
||||||
|
Symbol: "GBPUSD",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/forex/price/getAnFxPrice.go
Executable file
17
examples/forex/price/getAnFxPrice.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/forex"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the latest price for a given forex ticker
|
||||||
|
func GetAnFxPrice() {
|
||||||
|
forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := forexService.Price(&forex.PriceRequest{
|
||||||
|
Symbol: "GBPUSD",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/forex/quote/getAFxQuote.go
Executable file
17
examples/forex/quote/getAFxQuote.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/forex"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the latest quote for the forex
|
||||||
|
func GetAfxQuote() {
|
||||||
|
forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := forexService.Quote(&forex.QuoteRequest{
|
||||||
|
Symbol: "GBPUSD",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
148
examples/function/README.md
Executable file
148
examples/function/README.md
Executable file
@@ -0,0 +1,148 @@
|
|||||||
|
# Function
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Function/api](https://m3o.com/Function/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Deploy
|
||||||
|
|
||||||
|
Deploy a group of functions
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/function/api#Deploy](https://m3o.com/function/api#Deploy)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Deploy a group of functions
|
||||||
|
func DeployAfunction() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.Deploy(&function.DeployRequest{
|
||||||
|
Entrypoint: "helloworld",
|
||||||
|
Name: "my-first-func",
|
||||||
|
Project: "tests",
|
||||||
|
Repo: "github.com/m3o/nodejs-function-example",
|
||||||
|
Runtime: "nodejs14",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Call
|
||||||
|
|
||||||
|
Call a function by name
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/function/api#Call](https://m3o.com/function/api#Call)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Call a function by name
|
||||||
|
func CallAfunction() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.Call(&function.CallRequest{
|
||||||
|
Name: "my-first-func",
|
||||||
|
Request: map[string]interface{}{
|
||||||
|
},
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## List
|
||||||
|
|
||||||
|
List all the deployed functions
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/function/api#List](https://m3o.com/function/api#List)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List all the deployed functions
|
||||||
|
func ListFunctions() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.List(&function.ListRequest{
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Delete
|
||||||
|
|
||||||
|
Delete a function by name
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/function/api#Delete](https://m3o.com/function/api#Delete)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete a function by name
|
||||||
|
func DeleteAfunction() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.Delete(&function.DeleteRequest{
|
||||||
|
Name: "my-first-func",
|
||||||
|
Project: "tests",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Describe
|
||||||
|
|
||||||
|
Get the info for a deployed function
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/function/api#Describe](https://m3o.com/function/api#Describe)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the info for a deployed function
|
||||||
|
func DescribeFunctionStatus() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.Describe(&function.DescribeRequest{
|
||||||
|
Name: "my-first-func",
|
||||||
|
Project: "tests",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
18
examples/function/call/callAFunction.go
Executable file
18
examples/function/call/callAFunction.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Call a function by name
|
||||||
|
func CallAfunction() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.Call(&function.CallRequest{
|
||||||
|
Name: "my-first-func",
|
||||||
|
Request: map[string]interface{}{},
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
18
examples/function/delete/deleteAFunction.go
Executable file
18
examples/function/delete/deleteAFunction.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete a function by name
|
||||||
|
func DeleteAfunction() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.Delete(&function.DeleteRequest{
|
||||||
|
Name: "my-first-func",
|
||||||
|
Project: "tests",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
21
examples/function/deploy/deployAFunction.go
Executable file
21
examples/function/deploy/deployAFunction.go
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Deploy a group of functions
|
||||||
|
func DeployAfunction() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.Deploy(&function.DeployRequest{
|
||||||
|
Entrypoint: "helloworld",
|
||||||
|
Name: "my-first-func",
|
||||||
|
Project: "tests",
|
||||||
|
Repo: "github.com/m3o/nodejs-function-example",
|
||||||
|
Runtime: "nodejs14",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
18
examples/function/describe/describeFunctionStatus.go
Executable file
18
examples/function/describe/describeFunctionStatus.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the info for a deployed function
|
||||||
|
func DescribeFunctionStatus() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.Describe(&function.DescribeRequest{
|
||||||
|
Name: "my-first-func",
|
||||||
|
Project: "tests",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
15
examples/function/list/listFunctions.go
Executable file
15
examples/function/list/listFunctions.go
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/function"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List all the deployed functions
|
||||||
|
func ListFunctions() {
|
||||||
|
functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := functionService.List(&function.ListRequest{})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
64
examples/geocoding/README.md
Executable file
64
examples/geocoding/README.md
Executable file
@@ -0,0 +1,64 @@
|
|||||||
|
# Geocoding
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Geocoding/api](https://m3o.com/Geocoding/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Lookup
|
||||||
|
|
||||||
|
Lookup returns a geocoded address including normalized address and gps coordinates. All fields are optional, provide more to get more accurate results
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/geocoding/api#Lookup](https://m3o.com/geocoding/api#Lookup)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/geocoding"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Lookup returns a geocoded address including normalized address and gps coordinates. All fields are optional, provide more to get more accurate results
|
||||||
|
func GeocodeAnAddress() {
|
||||||
|
geocodingService := geocoding.NewGeocodingService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := geocodingService.Lookup(&geocoding.LookupRequest{
|
||||||
|
Address: "10 russell st",
|
||||||
|
City: "london",
|
||||||
|
Country: "uk",
|
||||||
|
Postcode: "wc2b",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Reverse
|
||||||
|
|
||||||
|
Reverse lookup an address from gps coordinates
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/geocoding/api#Reverse](https://m3o.com/geocoding/api#Reverse)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/geocoding"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reverse lookup an address from gps coordinates
|
||||||
|
func ReverseGeocodeLocation() {
|
||||||
|
geocodingService := geocoding.NewGeocodingService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := geocodingService.Reverse(&geocoding.ReverseRequest{
|
||||||
|
Latitude: 51.5123064,
|
||||||
|
Longitude: -0.1216235,
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
20
examples/geocoding/lookup/geocodeAnAddress.go
Executable file
20
examples/geocoding/lookup/geocodeAnAddress.go
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/geocoding"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Lookup returns a geocoded address including normalized address and gps coordinates. All fields are optional, provide more to get more accurate results
|
||||||
|
func GeocodeAnAddress() {
|
||||||
|
geocodingService := geocoding.NewGeocodingService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := geocodingService.Lookup(&geocoding.LookupRequest{
|
||||||
|
Address: "10 russell st",
|
||||||
|
City: "london",
|
||||||
|
Country: "uk",
|
||||||
|
Postcode: "wc2b",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
18
examples/geocoding/reverse/reverseGeocodeLocation.go
Executable file
18
examples/geocoding/reverse/reverseGeocodeLocation.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/geocoding"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reverse lookup an address from gps coordinates
|
||||||
|
func ReverseGeocodeLocation() {
|
||||||
|
geocodingService := geocoding.NewGeocodingService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := geocodingService.Reverse(&geocoding.ReverseRequest{
|
||||||
|
Latitude: 51.5123064,
|
||||||
|
Longitude: -0.1216235,
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
34
examples/gifs/README.md
Executable file
34
examples/gifs/README.md
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
# Gifs
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Gifs/api](https://m3o.com/Gifs/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Search
|
||||||
|
|
||||||
|
Search for a GIF
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/gifs/api#Search](https://m3o.com/gifs/api#Search)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/gifs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search for a GIF
|
||||||
|
func Search() {
|
||||||
|
gifsService := gifs.NewGifsService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := gifsService.Search(&gifs.SearchRequest{
|
||||||
|
Limit: 2,
|
||||||
|
Query: "dogs",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
18
examples/gifs/search/search.go
Executable file
18
examples/gifs/search/search.go
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/gifs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search for a GIF
|
||||||
|
func Search() {
|
||||||
|
gifsService := gifs.NewGifsService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := gifsService.Search(&gifs.SearchRequest{
|
||||||
|
Limit: 2,
|
||||||
|
Query: "dogs",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
33
examples/google/README.md
Executable file
33
examples/google/README.md
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
# Google
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Google/api](https://m3o.com/Google/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Search
|
||||||
|
|
||||||
|
Search for videos on Google
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/google/api#Search](https://m3o.com/google/api#Search)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/google"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search for videos on Google
|
||||||
|
func SearchForVideos() {
|
||||||
|
googleService := google.NewGoogleService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := googleService.Search(&google.SearchRequest{
|
||||||
|
Query: "how to make donuts",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
17
examples/google/search/searchForVideos.go
Executable file
17
examples/google/search/searchForVideos.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/google"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search for videos on Google
|
||||||
|
func SearchForVideos() {
|
||||||
|
googleService := google.NewGoogleService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := googleService.Search(&google.SearchRequest{
|
||||||
|
Query: "how to make donuts",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
60
examples/helloworld/README.md
Executable file
60
examples/helloworld/README.md
Executable file
@@ -0,0 +1,60 @@
|
|||||||
|
# Helloworld
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Helloworld/api](https://m3o.com/Helloworld/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Call
|
||||||
|
|
||||||
|
Call returns a personalised "Hello $name" response
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/helloworld/api#Call](https://m3o.com/helloworld/api#Call)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/helloworld"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Call returns a personalised "Hello $name" response
|
||||||
|
func CallTheHelloworldService() {
|
||||||
|
helloworldService := helloworld.NewHelloworldService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := helloworldService.Call(&helloworld.CallRequest{
|
||||||
|
Name: "John",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Stream
|
||||||
|
|
||||||
|
Stream returns a stream of "Hello $name" responses
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/helloworld/api#Stream](https://m3o.com/helloworld/api#Stream)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/helloworld"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Stream returns a stream of "Hello $name" responses
|
||||||
|
func StreamsAreCurrentlyTemporarilyNotSupportedInClients() {
|
||||||
|
helloworldService := helloworld.NewHelloworldService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := helloworldService.Stream(&helloworld.StreamRequest{
|
||||||
|
Name: "not supported",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
17
examples/helloworld/call/callTheHelloworldService.go
Executable file
17
examples/helloworld/call/callTheHelloworldService.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/helloworld"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Call returns a personalised "Hello $name" response
|
||||||
|
func CallTheHelloworldService() {
|
||||||
|
helloworldService := helloworld.NewHelloworldService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := helloworldService.Call(&helloworld.CallRequest{
|
||||||
|
Name: "John",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/helloworld"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Stream returns a stream of "Hello $name" responses
|
||||||
|
func StreamsAreCurrentlyTemporarilyNotSupportedInClients() {
|
||||||
|
helloworldService := helloworld.NewHelloworldService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := helloworldService.Stream(&helloworld.StreamRequest{
|
||||||
|
Name: "not supported",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
59
examples/holidays/README.md
Executable file
59
examples/holidays/README.md
Executable file
@@ -0,0 +1,59 @@
|
|||||||
|
# Holidays
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Holidays/api](https://m3o.com/Holidays/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Countries
|
||||||
|
|
||||||
|
Get the list of countries that are supported by this API
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/holidays/api#Countries](https://m3o.com/holidays/api#Countries)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/holidays"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the list of countries that are supported by this API
|
||||||
|
func ListCountries() {
|
||||||
|
holidaysService := holidays.NewHolidaysService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := holidaysService.Countries(&holidays.CountriesRequest{
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## List
|
||||||
|
|
||||||
|
List the holiday dates for a given country and year
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/holidays/api#List](https://m3o.com/holidays/api#List)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/holidays"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List the holiday dates for a given country and year
|
||||||
|
func GetHolidays() {
|
||||||
|
holidaysService := holidays.NewHolidaysService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := holidaysService.List(&holidays.ListRequest{
|
||||||
|
Year: 2022,
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
15
examples/holidays/countries/listCountries.go
Executable file
15
examples/holidays/countries/listCountries.go
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/holidays"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get the list of countries that are supported by this API
|
||||||
|
func ListCountries() {
|
||||||
|
holidaysService := holidays.NewHolidaysService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := holidaysService.Countries(&holidays.CountriesRequest{})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/holidays/list/getHolidays.go
Executable file
17
examples/holidays/list/getHolidays.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/holidays"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List the holiday dates for a given country and year
|
||||||
|
func GetHolidays() {
|
||||||
|
holidaysService := holidays.NewHolidaysService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := holidaysService.List(&holidays.ListRequest{
|
||||||
|
Year: 2022,
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
140
examples/id/README.md
Executable file
140
examples/id/README.md
Executable file
@@ -0,0 +1,140 @@
|
|||||||
|
# Id
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Id/api](https://m3o.com/Id/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Generate
|
||||||
|
|
||||||
|
Generate a unique ID. Defaults to uuid.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/id/api#Generate](https://m3o.com/id/api#Generate)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate a unique ID. Defaults to uuid.
|
||||||
|
func GenerateAuniqueId() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Generate(&id.GenerateRequest{
|
||||||
|
Type: "uuid",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Generate
|
||||||
|
|
||||||
|
Generate a unique ID. Defaults to uuid.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/id/api#Generate](https://m3o.com/id/api#Generate)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate a unique ID. Defaults to uuid.
|
||||||
|
func GenerateAshortId() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Generate(&id.GenerateRequest{
|
||||||
|
Type: "shortid",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Generate
|
||||||
|
|
||||||
|
Generate a unique ID. Defaults to uuid.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/id/api#Generate](https://m3o.com/id/api#Generate)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate a unique ID. Defaults to uuid.
|
||||||
|
func GenerateAsnowflakeId() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Generate(&id.GenerateRequest{
|
||||||
|
Type: "snowflake",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Generate
|
||||||
|
|
||||||
|
Generate a unique ID. Defaults to uuid.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/id/api#Generate](https://m3o.com/id/api#Generate)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate a unique ID. Defaults to uuid.
|
||||||
|
func GenerateAbigflakeId() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Generate(&id.GenerateRequest{
|
||||||
|
Type: "bigflake",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Types
|
||||||
|
|
||||||
|
List the types of IDs available. No query params needed.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/id/api#Types](https://m3o.com/id/api#Types)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List the types of IDs available. No query params needed.
|
||||||
|
func ListTheTypesOfIdsAvailable() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Types(&id.TypesRequest{
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
17
examples/id/generate/generateABigflakeId.go
Executable file
17
examples/id/generate/generateABigflakeId.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate a unique ID. Defaults to uuid.
|
||||||
|
func GenerateAbigflakeId() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Generate(&id.GenerateRequest{
|
||||||
|
Type: "bigflake",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/id/generate/generateAShortId.go
Executable file
17
examples/id/generate/generateAShortId.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate a unique ID. Defaults to uuid.
|
||||||
|
func GenerateAshortId() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Generate(&id.GenerateRequest{
|
||||||
|
Type: "shortid",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/id/generate/generateASnowflakeId.go
Executable file
17
examples/id/generate/generateASnowflakeId.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate a unique ID. Defaults to uuid.
|
||||||
|
func GenerateAsnowflakeId() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Generate(&id.GenerateRequest{
|
||||||
|
Type: "snowflake",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
17
examples/id/generate/generateAUniqueId.go
Executable file
17
examples/id/generate/generateAUniqueId.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate a unique ID. Defaults to uuid.
|
||||||
|
func GenerateAuniqueId() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Generate(&id.GenerateRequest{
|
||||||
|
Type: "uuid",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
15
examples/id/types/listTheTypesOfIdsAvailable.go
Executable file
15
examples/id/types/listTheTypesOfIdsAvailable.go
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List the types of IDs available. No query params needed.
|
||||||
|
func ListTheTypesOfIdsAvailable() {
|
||||||
|
idService := id.NewIdService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := idService.Types(&id.TypesRequest{})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
200
examples/image/README.md
Executable file
200
examples/image/README.md
Executable file
@@ -0,0 +1,200 @@
|
|||||||
|
# Image
|
||||||
|
|
||||||
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Image/api](https://m3o.com/Image/api).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
## Convert
|
||||||
|
|
||||||
|
Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64),
|
||||||
|
or by uploading the conversion result.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/image/api#Convert](https://m3o.com/image/api#Convert)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/image"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64),
|
||||||
|
// or by uploading the conversion result.
|
||||||
|
func ConvertApngImageToAjpegTakenFromAurlAndSavedToAurlOnMicrosCdn() {
|
||||||
|
imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := imageService.Convert(&image.ConvertRequest{
|
||||||
|
Name: "cat.jpeg",
|
||||||
|
Url: "somewebsite.com/cat.png",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Upload
|
||||||
|
|
||||||
|
Upload an image by either sending a base64 encoded image to this endpoint or a URL.
|
||||||
|
To resize an image before uploading, see the Resize endpoint.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/image/api#Upload](https://m3o.com/image/api#Upload)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/image"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Upload an image by either sending a base64 encoded image to this endpoint or a URL.
|
||||||
|
// To resize an image before uploading, see the Resize endpoint.
|
||||||
|
func UploadAbase64imageToMicrosCdn() {
|
||||||
|
imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := imageService.Upload(&image.UploadRequest{
|
||||||
|
Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAx0lEQVR4nOzaMaoDMQyE4ZHj+x82vVdhwQoTkzKQEcwP5r0ihT7sbjUTeAJ4HCegXQJYfOYefOyjDuBiz3yjwJBoCIl6QZOeUjTC1Ix1IxEJXF9+0KWsf2bD4bn37OO/c/wuQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9Sa/NG94Tf3j4WBdaxudMEkn4IM2rZBA0wBrvo7aOcpj2emXvLeVt0IGm0GVXUj91mvAAAA//+V2CZl+4AKXwAAAABJRU5ErkJggg==",
|
||||||
|
Name: "cat.jpeg",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Upload
|
||||||
|
|
||||||
|
Upload an image by either sending a base64 encoded image to this endpoint or a URL.
|
||||||
|
To resize an image before uploading, see the Resize endpoint.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/image/api#Upload](https://m3o.com/image/api#Upload)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/image"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Upload an image by either sending a base64 encoded image to this endpoint or a URL.
|
||||||
|
// To resize an image before uploading, see the Resize endpoint.
|
||||||
|
func UploadAnImageFromAurlToMicrosCdn() {
|
||||||
|
imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := imageService.Upload(&image.UploadRequest{
|
||||||
|
Name: "cat.jpeg",
|
||||||
|
Url: "somewebsite.com/cat.png",
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Resize
|
||||||
|
|
||||||
|
Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
|
||||||
|
If one of width or height is 0, the image aspect ratio is preserved.
|
||||||
|
Optional cropping.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/image/api#Resize](https://m3o.com/image/api#Resize)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/image"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
|
||||||
|
// If one of width or height is 0, the image aspect ratio is preserved.
|
||||||
|
// Optional cropping.
|
||||||
|
func Base64toHostedImage() {
|
||||||
|
imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := imageService.Resize(&image.ResizeRequest{
|
||||||
|
Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
|
||||||
|
Height: 100,
|
||||||
|
Name: "cat.png",
|
||||||
|
Width: 100,
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Resize
|
||||||
|
|
||||||
|
Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
|
||||||
|
If one of width or height is 0, the image aspect ratio is preserved.
|
||||||
|
Optional cropping.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/image/api#Resize](https://m3o.com/image/api#Resize)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/image"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
|
||||||
|
// If one of width or height is 0, the image aspect ratio is preserved.
|
||||||
|
// Optional cropping.
|
||||||
|
func Base64toBase64image() {
|
||||||
|
imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := imageService.Resize(&image.ResizeRequest{
|
||||||
|
Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
|
||||||
|
Height: 100,
|
||||||
|
Width: 100,
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Resize
|
||||||
|
|
||||||
|
Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
|
||||||
|
If one of width or height is 0, the image aspect ratio is preserved.
|
||||||
|
Optional cropping.
|
||||||
|
|
||||||
|
|
||||||
|
[https://m3o.com/image/api#Resize](https://m3o.com/image/api#Resize)
|
||||||
|
|
||||||
|
```go
|
||||||
|
package example
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/image"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
|
||||||
|
// If one of width or height is 0, the image aspect ratio is preserved.
|
||||||
|
// Optional cropping.
|
||||||
|
func Base64toBase64imageWithCropping() {
|
||||||
|
imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := imageService.Resize(&image.ResizeRequest{
|
||||||
|
Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
|
||||||
|
CropOptions: &image.CropOptions{
|
||||||
|
Height: 50,
|
||||||
|
Width: 50,
|
||||||
|
},
|
||||||
|
Height: 100,
|
||||||
|
Width: 100,
|
||||||
|
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/image"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64),
|
||||||
|
// or by uploading the conversion result.
|
||||||
|
func ConvertApngImageToAjpegTakenFromAurlAndSavedToAurlOnMicrosCdn() {
|
||||||
|
imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := imageService.Convert(&image.ConvertRequest{
|
||||||
|
Name: "cat.jpeg",
|
||||||
|
Url: "somewebsite.com/cat.png",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
21
examples/image/resize/base64ToBase64Image.go
Executable file
21
examples/image/resize/base64ToBase64Image.go
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/image"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
|
||||||
|
// If one of width or height is 0, the image aspect ratio is preserved.
|
||||||
|
// Optional cropping.
|
||||||
|
func Base64toBase64image() {
|
||||||
|
imageService := image.NewImageService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := imageService.Resize(&image.ResizeRequest{
|
||||||
|
Base64: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
|
||||||
|
Height: 100,
|
||||||
|
Width: 100,
|
||||||
|
})
|
||||||
|
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