Function service (#227)

This commit is contained in:
Janos Dobronszki
2021-10-11 11:54:53 +01:00
committed by GitHub
parent ee1674dda6
commit 599b418c20
36 changed files with 1988 additions and 41 deletions

103
clients/go/function/function.go Executable file
View File

@@ -0,0 +1,103 @@
package function
import (
"github.com/m3o/m3o-go/client"
)
func NewFunctionService(token string) *FunctionService {
return &FunctionService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}
type FunctionService struct {
client *client.Client
}
// Call a function
func (t *FunctionService) Call(request *CallRequest) (*CallResponse, error) {
rsp := &CallResponse{}
return rsp, t.client.Call("function", "Call", request, rsp)
}
//
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)
}
//
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 {
Name string `json:"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"`
// 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"`
// optional subfolder path
Subfolder string `json:"subfolder"`
}
type DeployResponse struct {
}
type Func struct {
// name of handler in source code
Entrypoint string `json:"entrypoint"`
// function name
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"`
// subfolder path to entrypoint
Subfolder string `json:"subfolder"`
}
type ListRequest struct {
// optional
Project string `json:"project"`
}
type ListResponse struct {
Functions []Func `json:"functions"`
}

View File

@@ -12,6 +12,7 @@ import (
"github.com/micro/services/clients/go/evchargers"
"github.com/micro/services/clients/go/file"
"github.com/micro/services/clients/go/forex"
"github.com/micro/services/clients/go/function"
"github.com/micro/services/clients/go/geocoding"
"github.com/micro/services/clients/go/helloworld"
"github.com/micro/services/clients/go/holidays"
@@ -56,6 +57,7 @@ func NewClient(token string) *Client {
EvchargersService: evchargers.NewEvchargersService(token),
FileService: file.NewFileService(token),
ForexService: forex.NewForexService(token),
FunctionService: function.NewFunctionService(token),
GeocodingService: geocoding.NewGeocodingService(token),
HelloworldService: helloworld.NewHelloworldService(token),
HolidaysService: holidays.NewHolidaysService(token),
@@ -100,6 +102,7 @@ type Client struct {
EvchargersService *evchargers.EvchargersService
FileService *file.FileService
ForexService *forex.ForexService
FunctionService *function.FunctionService
GeocodingService *geocoding.GeocodingService
HelloworldService *helloworld.HelloworldService
HolidaysService *holidays.HolidaysService

101
clients/ts/function/index.ts Executable file
View File

@@ -0,0 +1,101 @@
import * as m3o from "@m3o/m3o-node";
export class FunctionService {
private client: m3o.Client;
constructor(token: string) {
this.client = new m3o.Client({ token: token });
}
// Call a function
call(request: CallRequest): Promise<CallResponse> {
return this.client.call(
"function",
"Call",
request
) as Promise<CallResponse>;
}
//
delete(request: DeleteRequest): Promise<DeleteResponse> {
return this.client.call(
"function",
"Delete",
request
) as Promise<DeleteResponse>;
}
// Deploy a group of functions
deploy(request: DeployRequest): Promise<DeployResponse> {
return this.client.call(
"function",
"Deploy",
request
) as Promise<DeployResponse>;
}
//
list(request: ListRequest): Promise<ListResponse> {
return this.client.call(
"function",
"List",
request
) as Promise<ListResponse>;
}
}
export interface CallRequest {
// Name of the function
name?: string;
// Request body that will be passed to the function
request?: { [key: string]: any };
}
export interface CallResponse {
// Response body that the function returned
response?: { [key: string]: any };
}
export interface DeleteRequest {
name?: string;
project?: string;
}
export interface DeleteResponse {}
export interface DeployRequest {
// entry point, ie. handler name in the source code
// if not provided, defaults to the name parameter
entrypoint?: string;
// function name
name?: string;
// project is used for namespacing your functions
// optional. defaults to "default".
project?: string;
// github url to repo
repo?: string;
// optional subfolder path
subfolder?: string;
}
export interface DeployResponse {}
export interface Func {
// name of handler in source code
entrypoint?: string;
// function name
name?: string;
// project of function, optional
// defaults to literal "default"
// used to namespace functions
project?: string;
// git repo address
repo?: string;
// subfolder path to entrypoint
subfolder?: string;
}
export interface ListRequest {
// optional
project?: string;
}
export interface ListResponse {
functions?: Func[];
}

View File

@@ -9,6 +9,7 @@ import * as emoji from "./emoji";
import * as evchargers from "./evchargers";
import * as file from "./file";
import * as forex from "./forex";
import * as fx from "./function";
import * as geocoding from "./geocoding";
import * as helloworld from "./helloworld";
import * as holidays from "./holidays";
@@ -50,6 +51,7 @@ export class Client {
this.evchargersService = new evchargers.EvchargersService(token);
this.fileService = new file.FileService(token);
this.forexService = new forex.ForexService(token);
this.functionService = new fx.FunctionService(token);
this.geocodingService = new geocoding.GeocodingService(token);
this.helloworldService = new helloworld.HelloworldService(token);
this.holidaysService = new holidays.HolidaysService(token);
@@ -90,6 +92,7 @@ export class Client {
evchargersService: evchargers.EvchargersService;
fileService: file.FileService;
forexService: forex.ForexService;
functionService: fx.FunctionService;
geocodingService: geocoding.GeocodingService;
helloworldService: helloworld.HelloworldService;
holidaysService: holidays.HolidaysService;

View File

@@ -20,6 +20,7 @@
"./evchargers": "./dist/evchargers/index.js",
"./file": "./dist/file/index.js",
"./forex": "./dist/forex/index.js",
"./function": "./dist/function/index.js",
"./geocoding": "./dist/geocoding/index.js",
"./gifs": "./dist/gifs/index.js",
"./helloworld": "./dist/helloworld/index.js",
@@ -65,5 +66,5 @@
},
"type": "module",
"types": "dist/index.d.ts",
"version": "1.0.543"
"version": "1.0.544"
}