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":[
"andy@example.com",
"john@example.com"
]
}
JSON response on success:
{
"success": true
}
Retrieve the friends list for an email address.
JSON request:
{
"email": "andy@example.com"
}
JSON response on success:
{
"success": true,
"friends" : [
"john@example.com"
],
"count" : 1
}
Retrieve the common friends list between two email addresses.
JSON request:
{
"friends":[
"andy@example.com",
"john@example.com"
]
}
JSON response on success:
{
"success": true,
"friends":[
"common@example.com"
],
"count" : 1
}
Subscribe to updates from an email address.
That "subscribing to updates" is NOT equivalent to "adding a friend connection".
JSON request:
{
"requestor": "lisa@example.com",
"target": "john@example.com"
}
JSON response on success:
{
"success": true
}
Block updates from an email address.
Suppose "andy@example.com" blocks "john@example.com":
- 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": "andy@example.com",
"target": "john@example.com"
}
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. "john@example.com":
- has not blocked updates from "john@example.com", and
- at least one of the following:
- has a friend connection with "john@example.com"
- has subscribed to updates from "john@example.com"
- has been @mentioned in the update
JSON request:
{
"sender": "john@example.com",
"text": "Hello World! kate@example.com"
}
JSON response on success:
{
"success": true,
"recipients" : [
"lisa@example.com",
"kate@example.com"
]
}
- Demo.