Giter Club home page Giter Club logo

gocf's Introduction

GoCF

GoCF is a Golang Cloud Function Engine with Quickjs. Used for Business Gateway with JavaScript.

GoCF Architecture

GoCF has three modules:

  • mapi for master to push new api or modify exist api.
  • api is generated by script which upload by mapi.
  • vm which build with Quickjs
  • plugins which can be golang code invoked by JS

How to use

initalize the GoCF project:

  $ cd /the path of source code of GoCF
  $ ./build.sh // for develop use ./init.sh
  $ ./bin/gocf -n [number of vm] -p [path of local dir for cache script] -h [the host of master]

Mapi

there 3 api for master.

  • Get /mapi/check for heath check
  • Post /mapi/restart for restart vm or reset vm.
  • Post /mapi/scripts for upload new script or replace old script to build new api.

example

  # Request
  curl --location 'localhost:8000/mapi/scripts' \
  --header 'Content-Type: application/json' \
  --data '{
      "files":[
          {
              "path": "api/get.a.js",
              "script": "export default async function exec() {return {error: false, data: '\''Hello World'\''};};"
          }
      ]
  }'
  # Response
  {
    "error": false,
    "msg": "",
    "data":"Sucess"
  }

api

GoCF will generate api by the scripts which mapi upload with api url from path field.

So we can request the url /api/a and get the response like below:

  # Request
  curl --location 'localhost:8000/api/a'
  # Response
  {
    "data": "Hello World",
    "error": false
  }

Plugins

  // plugins/xxx.go
  plugins := make([]*gocf.Plugin, 0, 1)
	plugin := makePlugin("xx", func(args []*gocf.JSValue, this *gocf.JSValue) *gocf.JSValue {
		// do something
		return // something to JS
	})

	plugins = append(plugins, plugin)
  return plugins

  // plugins/index.go
  gocf.RegistPlugin("xxx", xxx())
  // call on js side
  xxx.xx()

License

Apache License

gocf's People

Contributors

ryouaki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.