Skip to content

Commit

Permalink
m3o client changed
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Nov 1, 2021
1 parent adaa98e commit 3c70d23
Show file tree
Hide file tree
Showing 44 changed files with 318 additions and 50 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -19,7 +19,6 @@ require (
github.com/google/uuid v1.2.0
github.com/gorilla/handlers v1.5.1
github.com/imdario/mergo v0.3.12
github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3
github.com/miekg/dns v1.1.43
github.com/nxadm/tail v1.4.8
github.com/opentracing/opentracing-go v1.2.0
Expand All @@ -30,6 +29,7 @@ require (
github.com/uber/jaeger-client-go v2.29.1+incompatible
github.com/uber/jaeger-lib v2.4.1+incompatible
github.com/urfave/cli/v2 v2.3.0
go.m3o.com v0.1.0
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
golang.org/x/net v0.0.0-20210510120150-4163338589ed
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Expand Up @@ -260,7 +260,6 @@ github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
Expand Down Expand Up @@ -343,8 +342,6 @@ github.com/liquidweb/go-lwApi v0.0.0-20190605172801-52a4864d2738/go.mod h1:0sYF9
github.com/liquidweb/go-lwApi v0.0.5/go.mod h1:0sYF9rMXb0vlG+4SzdiGMXHheCZxjguMq+Zb4S2BfBs=
github.com/liquidweb/liquidweb-cli v0.6.9/go.mod h1:cE1uvQ+x24NGUL75D0QagOFCG8Wdvmwu8aL9TLmA/eQ=
github.com/liquidweb/liquidweb-go v1.6.3/go.mod h1:SuXXp+thr28LnjEw18AYtWwIbWMHSUiajPQs8T9c/Rc=
github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3 h1:RVt7rqWl4al36BH9OY9k7IXnnooOP0Feanu1bed6X2s=
github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3/go.mod h1:vmeaYrKYpgVNhny/l7iH8mXS88S7ijUiYni3gZUrCq0=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
Expand Down Expand Up @@ -542,6 +539,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.m3o.com v0.1.0 h1:vYYcMtUzkkl8/zQcLIZFakBvNO/wSrMcNHRySAmEh9E=
go.m3o.com v0.1.0/go.mod h1:p8FdLqZH3R9a0y04qiMNT+clw69d3SxyQPFzCNbDRtk=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
2 changes: 1 addition & 1 deletion services/address/address.go
@@ -1,7 +1,7 @@
package address

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewAddressService(token string) *AddressService {
Expand Down
2 changes: 1 addition & 1 deletion services/answer/answer.go
@@ -1,7 +1,7 @@
package answer

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewAnswerService(token string) *AnswerService {
Expand Down
2 changes: 1 addition & 1 deletion services/cache/cache.go
@@ -1,7 +1,7 @@
package cache

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewCacheService(token string) *CacheService {
Expand Down
2 changes: 1 addition & 1 deletion services/crypto/crypto.go
@@ -1,7 +1,7 @@
package crypto

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewCryptoService(token string) *CryptoService {
Expand Down
2 changes: 1 addition & 1 deletion services/currency/currency.go
@@ -1,7 +1,7 @@
package currency

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewCurrencyService(token string) *CurrencyService {
Expand Down
18 changes: 17 additions & 1 deletion services/db/db.go
@@ -1,7 +1,7 @@
package db

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewDbService(token string) *DbService {
Expand All @@ -16,6 +16,12 @@ type DbService struct {
client *client.Client
}

// Count records in a table
func (t *DbService) Count(request *CountRequest) (*CountResponse, error) {
rsp := &CountResponse{}
return rsp, t.client.Call("db", "Count", request, rsp)
}

// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
func (t *DbService) Create(request *CreateRequest) (*CreateResponse, error) {
rsp := &CreateResponse{}
Expand Down Expand Up @@ -46,6 +52,16 @@ func (t *DbService) Update(request *UpdateRequest) (*UpdateResponse, error) {
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 {
// JSON encoded record or records (can be array or object)
Record map[string]interface{} `json:"record"`
Expand Down
2 changes: 1 addition & 1 deletion services/email/email.go
@@ -1,7 +1,7 @@
package email

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewEmailService(token string) *EmailService {
Expand Down
2 changes: 1 addition & 1 deletion services/emoji/emoji.go
@@ -1,7 +1,7 @@
package emoji

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewEmojiService(token string) *EmojiService {
Expand Down
2 changes: 1 addition & 1 deletion services/evchargers/evchargers.go
@@ -1,7 +1,7 @@
package evchargers

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewEvchargersService(token string) *EvchargersService {
Expand Down
2 changes: 1 addition & 1 deletion services/file/file.go
@@ -1,7 +1,7 @@
package file

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewFileService(token string) *FileService {
Expand Down
2 changes: 1 addition & 1 deletion services/forex/forex.go
@@ -1,7 +1,7 @@
package forex

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewForexService(token string) *ForexService {
Expand Down
151 changes: 151 additions & 0 deletions services/function/function.go
@@ -0,0 +1,151 @@
package function

import (
"go.m3o.com/client"
)

func NewFunctionService(token string) *FunctionService {
return &FunctionService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}

type FunctionService struct {
client *client.Client
}

// Call a function by name
func (t *FunctionService) Call(request *CallRequest) (*CallResponse, error) {
rsp := &CallResponse{}
return rsp, t.client.Call("function", "Call", request, rsp)
}

// Delete a function by name
func (t *FunctionService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
rsp := &DeleteResponse{}
return rsp, t.client.Call("function", "Delete", request, rsp)
}

// Deploy a group of functions
func (t *FunctionService) Deploy(request *DeployRequest) (*DeployResponse, error) {
rsp := &DeployResponse{}
return rsp, t.client.Call("function", "Deploy", request, rsp)
}

// Get the info for a deployed function
func (t *FunctionService) Describe(request *DescribeRequest) (*DescribeResponse, error) {
rsp := &DescribeResponse{}
return rsp, t.client.Call("function", "Describe", request, rsp)
}

// List all the deployed functions
func (t *FunctionService) List(request *ListRequest) (*ListResponse, error) {
rsp := &ListResponse{}
return rsp, t.client.Call("function", "List", request, rsp)
}

type CallRequest struct {
// Name of the function
Name string `json:"name"`
// Request body that will be passed to the function
Request map[string]interface{} `json:"request"`
}

type CallResponse struct {
// Response body that the function returned
Response map[string]interface{} `json:"response"`
}

type DeleteRequest struct {
// The name of the function
Name string `json:"name"`
// Optional project name
Project string `json:"project"`
}

type DeleteResponse struct {
}

type DeployRequest struct {
// entry point, ie. handler name in the source code
// if not provided, defaults to the name parameter
Entrypoint string `json:"entrypoint"`
// environment variables to pass in at runtime
EnvVars map[string]string `json:"envVars"`
// function name
Name string `json:"name"`
// project is used for namespacing your functions
// optional. defaults to "default".
Project string `json:"project"`
// github url to repo
Repo string `json:"repo"`
// runtime/language of the function
// eg: php74,
// nodejs6, nodejs8, nodejs10, nodejs12, nodejs14, nodejs16
// dotnet3
// java11
// ruby26, ruby27
// go111, go113, go116
// python37, python38, python39
Runtime string `json:"runtime"`
// optional subfolder path
Subfolder string `json:"subfolder"`
}

type DeployResponse struct {
}

type DescribeRequest struct {
// The name of the function
Name string `json:"name"`
// Optional project name
Project string `json:"project"`
}

type DescribeResponse struct {
// The function requested
Function *Func `json:"function"`
// The timeout for requests to the function
Timeout string `json:"timeout"`
// The time at which the function was updated
UpdatedAt string `json:"updatedAt"`
}

type Func struct {
// name of handler in source code
Entrypoint string `json:"entrypoint"`
// function name
// limitation: must be unique across projects
Name string `json:"name"`
// project of function, optional
// defaults to literal "default"
// used to namespace functions
Project string `json:"project"`
// git repo address
Repo string `json:"repo"`
// runtime/language of the function
// eg: php74,
// nodejs6, nodejs8, nodejs10, nodejs12, nodejs14, nodejs16
// dotnet3
// java11
// ruby26, ruby27
// go111, go113, go116
// python37, python38, python39
Runtime string `json:"runtime"`
// eg. ACTIVE, DEPLOY_IN_PROGRESS, OFFLINE etc
Status string `json:"status"`
// subfolder path to entrypoint
Subfolder string `json:"subfolder"`
}

type ListRequest struct {
// optional project name
Project string `json:"project"`
}

type ListResponse struct {
// List of functions deployed
Functions []Func `json:"functions"`
}
2 changes: 1 addition & 1 deletion services/geocoding/geocoding.go
@@ -1,7 +1,7 @@
package geocoding

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewGeocodingService(token string) *GeocodingService {
Expand Down
4 changes: 2 additions & 2 deletions services/gifs/gifs.go
@@ -1,7 +1,7 @@
package gifs

import (
"github.com/m3o/m3o-go/client"
"go.m3o.com/client"
)

func NewGifsService(token string) *GifsService {
Expand All @@ -16,7 +16,7 @@ type GifsService struct {
client *client.Client
}

// Search for a gif
// Search for a GIF
func (t *GifsService) Search(request *SearchRequest) (*SearchResponse, error) {
rsp := &SearchResponse{}
return rsp, t.client.Call("gifs", "Search", request, rsp)
Expand Down
48 changes: 48 additions & 0 deletions services/google/google.go
@@ -0,0 +1,48 @@
package google

import (
"go.m3o.com/client"
)

func NewGoogleService(token string) *GoogleService {
return &GoogleService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}

type GoogleService struct {
client *client.Client
}

// Search for videos on Google
func (t *GoogleService) Search(request *SearchRequest) (*SearchResponse, error) {
rsp := &SearchResponse{}
return rsp, t.client.Call("google", "Search", request, rsp)
}

type SearchRequest struct {
// Query to search for
Query string `json:"query"`
}

type SearchResponse struct {
// List of results for the query
Results []SearchResult `json:"results"`
}

type SearchResult struct {
// abridged version of this search result’s URL, e.g. www.exampe.com
DisplayUrl string `json:"displayUrl"`
// id of the result
Id string `json:"id"`
// kind of result; "search"
Kind string `json:"kind"`
// the result snippet
Snippet string `json:"snippet"`
// title of the result
Title string `json:"title"`
// the full url for the result
Url string `json:"url"`
}

0 comments on commit 3c70d23

Please sign in to comment.