Skip to content

Rx-11/go-wasp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-WASP

Go WebAssembly Serverless Platform

A lightweight serverless platform in Go for running WebAssembly (WASM) functions via REST APIs, with support for in-memory or Redis-based function registries, concurrent execution, and queuing.


Features

  • WASM Function Execution: Upload and invoke WebAssembly functions through RESTful endpoints.
  • Function Registry: Store and manage functions using in-memory or Redis-based registries.
  • Concurrency & Queues: Execute multiple function invocations concurrently and queue excess requests per function.
  • Timeouts & TTL: Control execution timeouts and cached function TTL.
  • JSON Output: Functions return JSON-formatted responses.
  • Modular Design: Easily extendable, suitable for testing serverless patterns.

Use Cases

  • WASM Function Testing: Upload and execute custom WebAssembly modules.
  • Serverless Experimentation: Prototype serverless architectures with concurrency, caching, and queues.
  • Custom FaaS Platforms: Build and test foundations for Function-as-a-Service systems.

Getting Started

Prerequisites

Configuration

Create a .env file in the project root:

SERVER_PORT=8080
REGISTRY_TYPE=memory          # memory or redis
REDIS_ADDR=localhost:6379
REDIS_PASSWORD=
REDIS_DB=0
DefaultTTL=0                  # TTL for cached functions in seconds (0 = unlimited)
DEFAULT_FUNC_CONCURRENCY=4    # Max concurrent executions per function
MAX_NODE_CONCURRENCY=0        # Max concurrent executions for the node (0 = unlimited)
QUEUE_SIZE_PER_FUNCTION=128   # Max queued requests per function
INVOKE_TIMEOUT_MS=5000        # Timeout per invocation in milliseconds

Running the Server

go run main.go

Server will start on http://localhost:8080.


REST API Endpoints

Method Path Description
POST /upload Upload a WASM file
POST /:name/invoke Invoke a function by name
GET /functions List uploaded functions

Sample WASM: Hello World

C Source (hello.c)

#include <stdio.h>

__attribute__((export_name("hello")))
void hello() {
    printf("{\"message\": \"hello world\"}\n");
    fflush(stdout);
}

Compile to WASM

& "C:\path\to\wasi-sdk\bin\clang.exe" `
  --target=wasm32-wasi `
  --sysroot="C:\path\to\wasi-sdk\share\wasi-sysroot" `
  -O2 hello.c -o hello.wasm

Upload the Function

curl.exe -X POST http://localhost:8080/upload -F "file=@hello.wasm" -F "name=hello"

Invoke the Function

curl.exe -X POST http://localhost:8080/hello/invoke -H "Content-Type: application/json" -d "{}"

Expected output:

{"message":"hello world"}

Project Structure

go-wasp/
├── api/            # HTTP API handlers
├── config/         # Configuration management
├── constants/      # Constant values and enums
├── executor/       # WASM function execution and dispatcher
├── internal/       # Internal utilities
├── registry/       # Function registry implementations
├── .env            # Environment variables
├── hello.wasm      # Sample WASM function (Hello World)
├── main.go         # Entry point
└── README.md       # Project documentation

License

MIT License — see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages