Skip to content

A simple Lisp-Style protocol for communication (golang version)

License

Notifications You must be signed in to change notification settings

lock-free/gopcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
junyu.chen
Oct 3, 2020
e1bac94 · Oct 3, 2020

History

29 Commits
Oct 3, 2020
Feb 28, 2019
Jun 11, 2019
Jun 11, 2019
Sep 20, 2019
Oct 3, 2020
Oct 3, 2020
Jun 21, 2019
Jun 21, 2019
Sep 20, 2019
Sep 20, 2019
Feb 4, 2019

Repository files navigation

gopcp

A simple Lisp-Style protocol for communication (golang version)

travis-ci build status

Features

  • lisp style composation

  • function sandbox. User can control every function and detail by providing the sandbox.

  • based on json grammer

Quick Example

import (
  "github.com/lock-free/gopcp"
  "errors"
)

// create sandbox
sandBox := gopcp.GetSandbox(map[string]*gopcp.BoxFunc{
	"add": gopcp.ToSandboxFun(func(args []interface{}, pcpServer *gopcpc.PcpServer) (interface{}, error) {
		var res float64
		for _, arg := range args {
			if val, ok := arg.(float64); !ok {
				return nil, errors.New("args should be int")
			} else {
				res += val
			}
		}
		return res, nil
	}),
})

pcpServer := NewPcpServer(sandbox)

// we can just use json array string
// output: 3
r1, e1 := pcpServer.Execute("[\"add\", 1, 2]")

// we can also use PcpClient, instead of raw string
var pcpClient = PcpClient{}
callText, jerr := pcpClient.ToJSON(pcpClient.Call("add", 1, 2))

r2, e2 := pcpServer.Execute(callText)

About

A simple Lisp-Style protocol for communication (golang version)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published