dione/rpc/rpc.go
2020-12-02 17:03:39 +03:00

20 lines
484 B
Go

package rpc
var rpcs = map[uint8]map[string]func(string) ([]byte, error){} // rpcType -> {rpcMethodName -> actual func var}
func RegisterRPC(rpcType uint8, rpcMethods map[string]func(string) ([]byte, error)) {
rpcs[rpcType] = rpcMethods
}
func GetRPCMethod(rpcType uint8, rpcMethodName string) func(string) ([]byte, error) {
rpcMethods, ok := rpcs[rpcType]
if !ok {
return nil
}
actualMethod, ok := rpcMethods[rpcMethodName]
if !ok {
return nil
}
return actualMethod
}