rpc_safe_guard_01/question.md
2023-07-13 17:39:26 +08:00

44 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 1. 简化思路
例如:
```javascript
// 1. 检查用户名是否已经注册
hasUser = rpc.call("com.swallow.user.checkUserName", user.name)
if (hasUser != null) {
rpc.error("code", "message")
}
// 2. 检查手机号是否已经注册
hasPhone = rpc.call("com.swallow.user.checkPhoneNumber", user.phoneNumber)
if (hasPhone != null) {
rpc.error("code", "message")
}
// 3. 创建用户
create = rpc.call("com.swallow.user.create", user)
if (create) {
rpc.success({ "data": create })
}
```
目前的简化思路就是我在后台只注册rpc参数并给rpc注册call/error等方法配置文件全部弃掉
## 2、call函数使用
- 第一个参数是要调用的rpc名字可以来自于rpc linker也可以来自于java service
- 第二个参数是写成类似于这样的来接受0个或多个参数的请求体请求体将会传递给rpc方法的请求参数
```javascript
arg = {
"name": "test",
"age": 12,
"other": "ssss"
}
rpc.call("com.swallow.user.create", arg)
```
## 3、条件限定
- go后台拿到rpc响应后是不是还需要根据条件限定对响应进行校验
- 例如HTML或者APP传递条件给我username != null我需要根据这个条件加个判断再返回响应给js。
## 4、前台传递的条件是单个还是多个