A Go library for generating event-based RPC endpoints.
Installation via Go Get:
go get github.com/dowlandaiello/Go-RpcifyInitialize an RPC Server:
import (
serverTypes github.com/dowlandaiello/Go-Rpcify/networking/types
)
server := serverTypes.NewServer("server") // Initialize serverInitialize a Call from a Method:
import (
github.com/dowlandaiello/Go-Rpcify/types
)
call, err := types.NewCall(method, "methodName") // Initialize call
if err != nil { // Check for errors
panic(err) // Panic
}Add a Call to an RPC Server:
server.Environment.AddCall(call) // Add callStart a Server:
server.StartServer() // Start ServerIn order to support the standard go net/rpc RPC server implementation, all call methods must
-
Be of an exported type
-
Be exported
-
Have two arguments (an arguments list struct, and a response pointer)
-
Have a return type of error
-
Have a mirroring standalone method with no arguments, and a return type of string and error (response, and error)
Connect to a Server via RPC:
client, err := rpc.DialHTTP("tcp", "localhost" + ":8081") // Connect to server
if err != nil { // Check for errors
panic(err) // Panic
}Run a Call via RPC:
var reply int // Init reply buffer
err = client.Call("Common.HelloWorld", &reply) // Call method
if err != nil { // Check for errors
panic(err) // Panic
}Run a Call via HTTP:
http://localhost:8080/call/$callEndpointRun Go via HTTP:
http://localhost:8080/call/$goCodeExample:
http://localhost:8080/call/fmt.Println("example")