All Projects → poga → spacer

poga / spacer

Licence: MIT license
🚀Serverless function platform for Lua

Programming Languages

lua
6591 projects
go
31211 projects - #10 most used programming language
javascript
184084 projects - #8 most used programming language
Dockerfile
14818 projects
CSS
56736 projects
shell
77523 projects

Projects that are alternatives of or similar to spacer

Upyun Resty
UPYUN's open source software for OpenResty development
Stars: ✭ 150 (+200%)
Mutual labels:  openresty
Dice
前后端分离Blog系统,采用Nuxt、Vue 2.x 和 SpringBoot 全家桶。
Stars: ✭ 222 (+344%)
Mutual labels:  openresty
dnmp
docker-compose部署LNMP环境 Nginx/Openresty、MySQL(5.7、8.0、8.1)、PHP7.4(8.0、5.6)、Redis5.0、PHPMyAdmin、Xdebug、RabbitMQ、Nacos
Stars: ✭ 138 (+176%)
Mutual labels:  openresty
Lua Resty Repl
Interactive console (REPL) for Openresty and luajit code
Stars: ✭ 165 (+230%)
Mutual labels:  openresty
Lua Resty Redis Connector
Connection utilities for lua-resty-redis
Stars: ✭ 186 (+272%)
Mutual labels:  openresty
Lapis
A web framework for Lua and OpenResty written in MoonScript
Stars: ✭ 2,621 (+5142%)
Mutual labels:  openresty
Lua Resty Auto Ssl
On the fly (and free) SSL registration and renewal inside OpenResty/nginx with Let's Encrypt.
Stars: ✭ 1,786 (+3472%)
Mutual labels:  openresty
hyper-content-db
A Kappa-style peer-to-peer content database, on top of hyperdrives.
Stars: ✭ 34 (-32%)
Mutual labels:  kappa-architecture
Lnmp
LEMP stack/LAMP stack/LNMP stack installation scripts for CentOS/Redhat Debian and Ubuntu
Stars: ✭ 2,488 (+4876%)
Mutual labels:  openresty
ngx-lua-images
OpenResty (nginx+lua)+Ceph+GraphicsMagick 动态生成处理图片
Stars: ✭ 34 (-32%)
Mutual labels:  openresty
Lua Resty Jit Uuid
Fast and dependency-free UUID library for LuaJIT/ngx_lua
Stars: ✭ 169 (+238%)
Mutual labels:  openresty
Orange
OpenResty/Nginx Gateway for API Monitoring and Management.
Stars: ✭ 2,208 (+4316%)
Mutual labels:  openresty
nginx-lua
Nginx 1.19+ with LUA support based on Alpine Linux, Amazon Linux, Debian, Fedora and Ubuntu.
Stars: ✭ 112 (+124%)
Mutual labels:  openresty
Oneinstack
OneinStack - A PHP/JAVA Deployment Tool
Stars: ✭ 1,983 (+3866%)
Mutual labels:  openresty
wired-vpn
WireGuard behind OIDC
Stars: ✭ 21 (-58%)
Mutual labels:  openresty
Ngx Oauth
OAuth 2.0 proxy for nginx written in Lua.
Stars: ✭ 146 (+192%)
Mutual labels:  openresty
Apicast
3scale API Gateway
Stars: ✭ 225 (+350%)
Mutual labels:  openresty
lua-resty-http2
The HTTP/2 Protocol (Client Side) Implementation for OpenResty.
Stars: ✭ 73 (+46%)
Mutual labels:  openresty
casper
Yelp's internal caching proxy, powered by Nginx and OpenResty at its core
Stars: ✭ 81 (+62%)
Mutual labels:  openresty
mocka
Mocka - The complete testing framework for LUA and Nginx
Stars: ✭ 26 (-48%)
Mutual labels:  openresty

Spacer

stability-experimental Go Report Card

Serverless function platform for Lua

Features

  • High-performance non-blocking functions.
  • Fast edit-save-reload development cycle: No redeployment or rebuilding image is needed.
  • Platform agnostic: From a simple PostgreSQL database to a complex Kubernetes clusters with Apache Kafka. Spacer can run on most platforms.

Synopsis

Here's a minimal spacer project.

You write a function:

-- app/hello.lua
local G = function (args)
    return "Hello from Spacer!"
end

return G

...and define how to expose it to the internet:

-- app/gateway.lua
local R = {
    -- HTTP Method, Path, Function Name
    {"GET", "/hello", "hello"}
}

return R

...then start the project.

$ ./bin/dev.sh

Test the function.

$ curl localhost:3000/hello
{"data":"Hello from Spacer!"}

That's it!

Install

The easiest way would be using the provided Dockerfile.

To install from source:

  1. Install Dependencies

If you're on a Mac, brew install openresty/brew/openresty librdkafka should get everything you need.

  1. Install Spacer

Spacer is written in Go. It can be installed via go get.

$ go get -u github.com/poga/spacer

Quick Start

Create a spacer project:

$ spacer init ~/spacer-hello

Start the development server:

$ cd ~/spacer-hello
$ ./bin/dev.sh

Open http://localhost:3000/hello and you should see spacer working.

Hello World

Functions in spacer are written in Lua, a simple dynamic langauge. Here's a hello world function:

-- app/hello.lua
local G = function (args)
    return "Hello from Spacer!"
end

return G

Every function takes one argument: args. For detail, check the Functions section.

Test

Spacer have built-in test framework. Run all tests with command ./bin/test.sh.

$ ./bin/test.sh
1..1
# Started on Mon Feb 12 17:46:48 2018
# Starting class: testT
ok     1	testT.test_ret
# Ran 1 tests in 0.000 seconds, 1 success, 0 failures

See test/test_hello.lua for example.

Functions

Code in spacer are organized by functions. For now, spacer only support Lua as the programming language.

Functions are the main abstraction in spacer. Functions are composed together to build a complex application.

There are 2 way to invoke other functions from a function. The first is the simplest: just call it like a normal lua function.

-- app/bar.lua
local G = function (args)
  return params.val + 42
end

-- app/foo.lua
local bar = require "bar"

local G = function (args)
  return 100 + bar({val = 1}) -- returns 143
end

The second way is use flow.call, which emulate a http request between two function. It's useful when you want to create seperated tracings for two function.

local flow = require "flow"

local G = function (args)
  return flow.call("bar", {val = 1}) -- returns 143
end

It's called flow since the primary usage of it is to trace the flow between functions.

Exposing Functions to the Public

Functions are exposed to the public through a gateway. You can define gateway in gateway.lua.

local _R = {
    -- HTTP Method, Path, Function Name
    {"GET", "/hello", "hello"},

    -- users resources
    {"GET", "/users", "controllers/users/get"},
    {"PUT", "/users/:id", "controllers/users/put"},

    -- teams resources
    {"POST", "/teams", "create_teams"},
    {"GET", "/teams/:id", "get_team"},
    {"PUT", "/teams/:id", "put_team"},
    {"DELETE", "/teams/:id", "delete_team"},

    -- registration
    {"POST", "/register", "controllers/users/create"}
}

return _R

When invoking a function via HTTP request, query params, route params, and post body(json) are all grouped into an args table and passed to the function.

Error handling

An error is corresponding to HTTP 4xx status code: something went wrong on the caller side. In this case, return the error as the second returned value

local G = function (args)
  return nil, "invalid password"
end

If an unexpected exception happepend, use the error() function to return it. Spacer will return the error with HTTP 500 status code.

local G = function (args)
  local conn = db.connect()
  if conn == nil then
    error("unable to connect to DB")
  end
end

Event, Trigger, and Kappa Architecture

Serverless programming is about events. Fuctions are working together through a series of events.

Spacer use Kappa Architecture to provide a unified architecture for both events and data storage.

Event and Topic

Events are organized with topics. Topics need to be defined in the config config/application.yml.

To emit a event, use the built-in topics library.

local topics = require "topics"

local G = function (args)
  topics.append("EVENT_NAME", { [EVENT_KEY] = EVENT_PAYLOAD })
end

return G

Trigger

Triggers are just functions. You can set a function as a trigger by setting them in the config config/application.yml.

Log, Kappa Architecture, and Replay

Events in spacer are permanently stored in the specified storage (by default we use PostgreSQL as storage).

Libraries Search Path

You can require lua module under app/ and lib/ directly.

-- requiring app/foo.lua
local m = require "foo"

Directories can be used to organize your modules.

-- requiring app/models/foo.lua
local m = require "models/foo"

Contribute

To build spacer from source:

$ git clone [email protected]:poga/spacer.git
$ make
$ go install  // if you want to put it into your path

License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].