2020-08-03 20:01:38 +00:00
|
|
|
package rpc
|
|
|
|
|
2020-12-02 14:03:39 +00:00
|
|
|
var rpcs = map[uint8]map[string]func(string) ([]byte, error){} // rpcType -> {rpcMethodName -> actual func var}
|
2020-11-23 21:59:27 +00:00
|
|
|
|
2020-12-02 14:03:39 +00:00
|
|
|
func RegisterRPC(rpcType uint8, rpcMethods map[string]func(string) ([]byte, error)) {
|
2020-11-23 21:59:27 +00:00
|
|
|
rpcs[rpcType] = rpcMethods
|
|
|
|
}
|
|
|
|
|
2020-12-02 14:03:39 +00:00
|
|
|
func GetRPCMethod(rpcType uint8, rpcMethodName string) func(string) ([]byte, error) {
|
2020-11-23 21:59:27 +00:00
|
|
|
rpcMethods, ok := rpcs[rpcType]
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
actualMethod, ok := rpcMethods[rpcMethodName]
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return actualMethod
|
2020-08-03 20:01:38 +00:00
|
|
|
}
|