tigerbalm

package module
v0.0.0-...-1256235 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 13 Imported by: 0

README

TigerBalm

Jack of all trades, A Faas(function as a service) framework, to custom a plugin by adding a javascript snippet, to activate the snippet by killing pid with signal hangup(kill -HUP $pid) instead of further compiling.

Currently support:

  • env
  • log
  • http
  • kafka

To run tigerbalm

git clone https://github.com/jumboframes/tigerbalm
make
./tigerbalm -f ./tigerbalm.yaml

To start customizing a snippet

A proxy
var http = require("http")
var log = require("log")
var env = require("env")

function register() {
    var route = new Object();
    route.match = new Object();
    route.match.path = "/foo";
    route.match.method = "GET";
    route.handler = httpHandler;
    var registration = Object();
    registration.route = route;
    return registration
}

function httpHandler(request) {
    log.Debugf("incoming request, host: %s, url: %s",
        request["Host"], request["Url"])

    req = {
        "Method": "GET",
        "Host": env.Get("GOOGLE"),
        "Path": "/bar",
    }
    data = http.DoRequest(req)
    log.Debugf("do request, host: %s, body: %s", env.Get("GOOGLE"), data["Body"])
    return {
        "Status": 200,
        "Body": "Austin Zhai"
    }
}

A kafka logic broker
var log = require("log")
var producer = require("producer")

function register() {
    registration = {
        "consume": {
            "match": {
                "topic": "austin",
                "group": "zhai"
            },
            "handler": kafkaHandler,
        }
    }
    return registration
}

function kafkaHandler(msg) {
    log.Debugf("incoming message, topic: %s, group: %s",
        msg["Topic"], msg["Group"])
    msg = {
        "Topic": "austin_relay",
        "Payload": msg["Payload"],
    }
    ret = producer.Produce(msg)
    log.Debugf("relay message to topic: %s %v", "austin_relay", ret)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRegisterNotFunction = errors.New("register not function")
	ErrRegisterNotObject   = errors.New("register not object")
	ErrNewInterpreter      = errors.New("new interpreter error")
	ErrNoSuchSlot          = errors.New("no such slot")
)
View Source
var (
	ReservedFiniSignals = []os.Signal{
		os.Kill,
		os.Interrupt,
		syscall.SIGTERM,
	}
)

Functions

func Init

func Init() error

Types

type Config

type Config struct {
	Web struct {
		Addr string `yaml:"addr"`
	} `yaml:"web"`

	Kafka struct {
		Enable   bool     `yaml:"enable"`
		Brokers  []string `yaml:"brokers"`
		Consumer struct {
			Group struct {
				Session struct {
					Timeout time.Duration `yaml:"timeout"`
				} `yaml:"session`
				Heartbeat struct {
					Interval time.Duration `yaml:"interval"`
				} `yaml:"heartbeat"`
			} `yaml:"group"`
			Offsets struct {
				Initial int64 `yaml:"initial"`
			} `yaml:"offsets"`
		} `yaml:"consumer"`
	} `yaml:"kafka"`

	Plugin struct {
		Path      string `yaml:"path"`
		WatchPath bool   `yaml:"watch_path"`
		Log       struct {
			Enable   bool   `yaml:"enable"`
			Path     string `yaml:"path"`
			Level    string `yaml:"level"`
			MaxSize  int64  `yaml:"maxsize"`
			MaxRolls uint   `yaml:"maxrolls"`
		} `yaml:"log"`
	} `yaml:"plugin"`

	Log struct {
		Level    string `yaml:"level"`
		File     string `yaml:"file"`
		MaxSize  int64  `yaml:"maxsize"`
		MaxRolls uint   `yaml:"maxrolls"`
	} `yaml:"log"`

	Env []struct {
		Name  string `yaml:"name"`
		Value string `yaml:"value"`
	} `yaml:"env"`
}
var (
	Conf      *Config
	RotateLog *rotatelogs.RotateLogs
)

type Notifier

type Notifier interface {
	Notify(os.Signal)
}

type Signal

type Signal struct {
	// contains filtered or unexported fields
}

func NewSignal

func NewSignal(options ...SignalOption) *Signal

func (*Signal) Add

func (sig *Signal) Add(sg os.Signal, nts ...Notifier)

func (*Signal) Wait

func (sig *Signal) Wait(ctx context.Context)

type SignalOption

type SignalOption func(*Signal)

func OptionSignalCancel

func OptionSignalCancel(cancel context.CancelFunc) SignalOption

Directories

Path Synopsis
server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL