For any application with a need to build its own social network, "Friends Management" is a common requirement which ussually starts off simple but can grow in complexity depending on the application's use case. Usually, applications would start with features like "Friend", "Unfriend", "Block", "Receive Updates" etc.
- Swagger 注释说明
- swagger/main.go 生成Swagger文档
- 配置文件config/app_config.ini,首次运行时创建或自行创建
app_config.ini
#数据库连接
dburl = postgres://user:password@ip:port/dbname?sslmode=disable
#端口 predix时为cloud
port = port
#Swagger Basepath
swagger_basepath = http://ip:port
-
运行后 Swagger UI 地址:http://ip:port/swagger-ui/
https://wangjingzhu.run.aws-jp01-pr.ice.predix.io/swagger-ui/
Create a friend connection between two email addresses.
JSON request:
{
"friends":[
"[email protected]",
"[email protected]"
]
}
JSON response on success:
{
"success": true
}
Retrieve the friends list for an email address.
JSON request:
{
"email": "[email protected]"
}
JSON response on success:
{
"success": true,
"friends" : [
"[email protected]"
],
"count" : 1
}
Retrieve the common friends list between two email addresses.
JSON request:
{
"friends":[
"[email protected]",
"[email protected]"
]
}
JSON response on success:
{
"success": true,
"friends":[
"[email protected]"
],
"count" : 1
}
Subscribe to updates from an email address.
That "subscribing to updates" is NOT equivalent to "adding a friend connection".
JSON request:
{
"requestor": "[email protected]",
"target": "[email protected]"
}
JSON response on success:
{
"success": true
}
Block updates from an email address.
Suppose "[email protected]" blocks "[email protected]":
- if they are connected as friends, then "andy" will no longer receive notifications from "john"
- if they are not connected as friends, then no new friends connection can be added
JSON request:
{
"requestor": "[email protected]",
"target": "[email protected]"
}
JSON response on success:
{
"success": true
}
Retrieve all email addresses that can receive updates from an email address.
Eligibility for receiving updates from i.e. "[email protected]":
- has not blocked updates from "[email protected]", and
- at least one of the following:
- has a friend connection with "[email protected]"
- has subscribed to updates from "[email protected]"
- has been @mentioned in the update
JSON request:
{
"sender": "[email protected]",
"text": "Hello World! [email protected]"
}
JSON response on success:
{
"success": true,
"recipients" : [
"[email protected]",
"[email protected]"
]
}
- Demo.