Browse Source

redis加入

May1145 1 year ago
parent
commit
dc0dfc8681

+ 16 - 0
trading-go/bin/config/config.yml

@@ -0,0 +1,16 @@
+web:
+  port : :8084
+mysql:
+  host: 127.0.0.1
+  port: 3306
+  database: trade
+  username: root
+  password: Cherry1145
+  charset: utf8
+redis:
+  addr: localhost:6379
+  password:
+  db: 0
+  poolsize: 20
+time:
+  time: 2023-8-16

+ 1335 - 0
trading-go/bin/docs/docs.go

@@ -0,0 +1,1335 @@
+// Code generated by swaggo/swag. DO NOT EDIT.
+
+package docs
+
+import "github.com/swaggo/swag"
+
+const docTemplate = `{
+    "schemes": {{ marshal .Schemes }},
+    "swagger": "2.0",
+    "info": {
+        "description": "{{escape .Description}}",
+        "title": "{{.Title}}",
+        "termsOfService": "http://swagger.io/terms/",
+        "contact": {},
+        "license": {
+            "name": "Apache 2.0",
+            "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
+        },
+        "version": "{{.Version}}"
+    },
+    "host": "{{.Host}}",
+    "basePath": "{{.BasePath}}",
+    "paths": {
+        "/appraise/create": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "评论模块"
+                ],
+                "summary": "创建评论",
+                "parameters": [
+                    {
+                        "description": "评价信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.AppraiseJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/appraise/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "评论模块"
+                ],
+                "summary": "删除评论",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "评论id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/appraise/revise": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "评论模块"
+                ],
+                "summary": "修改评论",
+                "parameters": [
+                    {
+                        "description": "评价信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.Appraise"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/appraise/user": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "评论模块"
+                ],
+                "summary": "获取用户评价",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "id",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/category": {
+            "get": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "分类模块"
+                ],
+                "summary": "获取所有分类",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/category/create": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "分类模块"
+                ],
+                "summary": "创建分类",
+                "parameters": [
+                    {
+                        "description": "分类数据",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.CategoryJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/category/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "分类模块"
+                ],
+                "summary": "根据分类id删除某个分类",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "分类id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "与服务端进行websocket连接,请使用postman测试",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat/from": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取未过期且来源为特定用户的聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat/to": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取未过期且目标为特定用户的聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/category/{page}/{pageSize}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "按分类查找商品并分页显示",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品分类id",
+                        "name": "category",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/create": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "创建商品",
+                "parameters": [
+                    {
+                        "description": "商品信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.GoodsJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "删除商品",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "商品id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/detail/{id}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "获取商品详细信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "商品id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/recommend/{page}/{pageSize}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "分页获取推荐商品",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "id",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/revise": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "修改商品信息",
+                "parameters": [
+                    {
+                        "description": "商品信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.Goods"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/search/{page}/{pageSize}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "搜索商品并分页显示",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "搜素关键词",
+                        "name": "keyword",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/user/{id}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "获取某个用户的所有商品",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/{page}/{pageSize}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "获取所有商品",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/message": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "信息模块"
+                ],
+                "summary": "传入用户id获取用户消息记录",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/message/conv": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "信息模块"
+                ],
+                "summary": "传入用户id和聊天对象id获取消息记录",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "对象id",
+                        "name": "targetId",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "获取所有订单",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order/create": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "创建订单",
+                "parameters": [
+                    {
+                        "description": "订单信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.OrderJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "删除订单",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "订单id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order/revise": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "修改订单的状态",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "订单id",
+                        "name": "id",
+                        "in": "formData",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "订单状态",
+                        "name": "state",
+                        "in": "formData",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order/user": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "获取用户的所有订单",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "id",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/pic": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "图片模块"
+                ],
+                "summary": "获取所有图片",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/pic/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "图片模块"
+                ],
+                "summary": "删除图片",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "图片id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/pic/upload": {
+            "post": {
+                "consumes": [
+                    "multipart/form-data"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "图片模块"
+                ],
+                "summary": "上传图片",
+                "parameters": [
+                    {
+                        "type": "file",
+                        "description": "图片",
+                        "name": "pic",
+                        "in": "formData",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/relation/bad": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户关系模块"
+                ],
+                "summary": "传入用户id获取用户黑名单列表",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/relation/create": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户关系模块"
+                ],
+                "summary": "添加用户间的关系,关系类型有1:好友关系,2:黑名单关系",
+                "parameters": [
+                    {
+                        "description": "关系数据",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.RelationJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/relation/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户关系模块"
+                ],
+                "summary": "根据关系id删除关系",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "关系id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/relation/friend": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户关系模块"
+                ],
+                "summary": "传入用户id获取用户好友列表",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/user/info": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "获取用户信息",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/user/login": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "登录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "微信ID",
+                        "name": "vid",
+                        "in": "formData"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/user/modify": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "修改用户信息",
+                "parameters": [
+                    {
+                        "description": "用户信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.User"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/user/register": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "创建用户",
+                "parameters": [
+                    {
+                        "description": "用户信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.UserJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        }
+    },
+    "definitions": {
+        "model.Appraise": {
+            "type": "object",
+            "properties": {
+                "buyerId": {
+                    "type": "integer"
+                },
+                "content": {
+                    "type": "string"
+                },
+                "goodsId": {
+                    "type": "integer"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "star": {
+                    "type": "integer"
+                },
+                "time": {
+                    "type": "integer"
+                }
+            }
+        },
+        "model.AppraiseJson": {
+            "type": "object",
+            "properties": {
+                "buyerId": {
+                    "type": "integer"
+                },
+                "content": {
+                    "type": "string"
+                },
+                "goodsId": {
+                    "type": "integer"
+                },
+                "star": {
+                    "type": "integer"
+                },
+                "time": {
+                    "type": "integer"
+                }
+            }
+        },
+        "model.CategoryJson": {
+            "type": "object",
+            "properties": {
+                "name": {
+                    "type": "string"
+                },
+                "pic": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.Goods": {
+            "type": "object",
+            "properties": {
+                "desc": {
+                    "type": "string"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "integrity": {
+                    "type": "integer"
+                },
+                "ownerId": {
+                    "type": "integer"
+                },
+                "picId": {
+                    "type": "integer"
+                },
+                "place": {
+                    "type": "string"
+                },
+                "price": {
+                    "type": "integer"
+                },
+                "state": {
+                    "type": "integer"
+                },
+                "title": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.GoodsJson": {
+            "type": "object",
+            "properties": {
+                "categories": {
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
+                "desc": {
+                    "type": "string"
+                },
+                "integrity": {
+                    "type": "integer"
+                },
+                "ownerId": {
+                    "type": "integer"
+                },
+                "pic_id": {
+                    "type": "integer"
+                },
+                "place": {
+                    "type": "string"
+                },
+                "price": {
+                    "type": "integer"
+                },
+                "state": {
+                    "type": "integer"
+                },
+                "title": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.OrderJson": {
+            "type": "object",
+            "properties": {
+                "buyerId": {
+                    "type": "integer"
+                },
+                "goodsId": {
+                    "type": "integer"
+                },
+                "phone": {
+                    "type": "string"
+                },
+                "place": {
+                    "type": "string"
+                },
+                "state": {
+                    "type": "integer"
+                },
+                "time": {
+                    "type": "integer"
+                }
+            }
+        },
+        "model.RelationJson": {
+            "type": "object",
+            "properties": {
+                "owner": {
+                    "type": "integer"
+                },
+                "target": {
+                    "type": "integer"
+                },
+                "type": {
+                    "type": "integer"
+                }
+            }
+        },
+        "model.User": {
+            "type": "object",
+            "properties": {
+                "avatar": {
+                    "type": "string"
+                },
+                "name": {
+                    "type": "string"
+                },
+                "phone": {
+                    "type": "string"
+                },
+                "uid": {
+                    "type": "integer"
+                },
+                "vid": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.UserJson": {
+            "type": "object",
+            "properties": {
+                "avatar": {
+                    "type": "string"
+                },
+                "name": {
+                    "type": "string"
+                },
+                "phone": {
+                    "type": "string"
+                },
+                "vid": {
+                    "type": "string"
+                }
+            }
+        },
+        "response.Response": {
+            "type": "object",
+            "properties": {
+                "code": {
+                    "type": "integer"
+                },
+                "data": {},
+                "message": {
+                    "type": "string"
+                }
+            }
+        }
+    }
+}`
+
+// SwaggerInfo holds exported Swagger Info so clients can modify it
+var SwaggerInfo = &swag.Spec{
+	Version:          "1.0",
+	Host:             "127.0.0.1:8084",
+	BasePath:         "/WeChatTrading/trading-go",
+	Schemes:          []string{},
+	Title:            "二手交易",
+	Description:      "一个基于微信小程序的校园二手交易平台的api文档",
+	InfoInstanceName: "swagger",
+	SwaggerTemplate:  docTemplate,
+	LeftDelim:        "{{",
+	RightDelim:       "}}",
+}
+
+func init() {
+	swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
+}

+ 1310 - 0
trading-go/bin/docs/swagger.json

@@ -0,0 +1,1310 @@
+{
+    "swagger": "2.0",
+    "info": {
+        "description": "一个基于微信小程序的校园二手交易平台的api文档",
+        "title": "二手交易",
+        "termsOfService": "http://swagger.io/terms/",
+        "contact": {},
+        "license": {
+            "name": "Apache 2.0",
+            "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
+        },
+        "version": "1.0"
+    },
+    "host": "127.0.0.1:8084",
+    "basePath": "/WeChatTrading/trading-go",
+    "paths": {
+        "/appraise/create": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "评论模块"
+                ],
+                "summary": "创建评论",
+                "parameters": [
+                    {
+                        "description": "评价信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.AppraiseJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/appraise/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "评论模块"
+                ],
+                "summary": "删除评论",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "评论id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/appraise/revise": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "评论模块"
+                ],
+                "summary": "修改评论",
+                "parameters": [
+                    {
+                        "description": "评价信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.Appraise"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/appraise/user": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "评论模块"
+                ],
+                "summary": "获取用户评价",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "id",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/category": {
+            "get": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "分类模块"
+                ],
+                "summary": "获取所有分类",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/category/create": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "分类模块"
+                ],
+                "summary": "创建分类",
+                "parameters": [
+                    {
+                        "description": "分类数据",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.CategoryJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/category/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "分类模块"
+                ],
+                "summary": "根据分类id删除某个分类",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "分类id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "与服务端进行websocket连接,请使用postman测试",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat/from": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取未过期且来源为特定用户的聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat/to": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取未过期且目标为特定用户的聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/category/{page}/{pageSize}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "按分类查找商品并分页显示",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品分类id",
+                        "name": "category",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/create": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "创建商品",
+                "parameters": [
+                    {
+                        "description": "商品信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.GoodsJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "删除商品",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "商品id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/detail/{id}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "获取商品详细信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "商品id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/recommend/{page}/{pageSize}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "分页获取推荐商品",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "id",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/revise": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "修改商品信息",
+                "parameters": [
+                    {
+                        "description": "商品信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.Goods"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/search/{page}/{pageSize}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "搜索商品并分页显示",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "搜素关键词",
+                        "name": "keyword",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/user/{id}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "获取某个用户的所有商品",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/goods/{page}/{pageSize}": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "获取所有商品",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/message": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "信息模块"
+                ],
+                "summary": "传入用户id获取用户消息记录",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/message/conv": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "信息模块"
+                ],
+                "summary": "传入用户id和聊天对象id获取消息记录",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "对象id",
+                        "name": "targetId",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "获取所有订单",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order/create": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "创建订单",
+                "parameters": [
+                    {
+                        "description": "订单信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.OrderJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "删除订单",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "订单id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order/revise": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "修改订单的状态",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "订单id",
+                        "name": "id",
+                        "in": "formData",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "订单状态",
+                        "name": "state",
+                        "in": "formData",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/order/user": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "订单模块"
+                ],
+                "summary": "获取用户的所有订单",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "id",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/pic": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "图片模块"
+                ],
+                "summary": "获取所有图片",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/pic/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "图片模块"
+                ],
+                "summary": "删除图片",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "图片id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/pic/upload": {
+            "post": {
+                "consumes": [
+                    "multipart/form-data"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "图片模块"
+                ],
+                "summary": "上传图片",
+                "parameters": [
+                    {
+                        "type": "file",
+                        "description": "图片",
+                        "name": "pic",
+                        "in": "formData",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/relation/bad": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户关系模块"
+                ],
+                "summary": "传入用户id获取用户黑名单列表",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/relation/create": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户关系模块"
+                ],
+                "summary": "添加用户间的关系,关系类型有1:好友关系,2:黑名单关系",
+                "parameters": [
+                    {
+                        "description": "关系数据",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.RelationJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/relation/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户关系模块"
+                ],
+                "summary": "根据关系id删除关系",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "关系id",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/relation/friend": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户关系模块"
+                ],
+                "summary": "传入用户id获取用户好友列表",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/user/info": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "获取用户信息",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/user/login": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "登录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "微信ID",
+                        "name": "vid",
+                        "in": "formData"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/user/modify": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "修改用户信息",
+                "parameters": [
+                    {
+                        "description": "用户信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.User"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/user/register": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "创建用户",
+                "parameters": [
+                    {
+                        "description": "用户信息",
+                        "name": "json",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/model.UserJson"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        }
+    },
+    "definitions": {
+        "model.Appraise": {
+            "type": "object",
+            "properties": {
+                "buyerId": {
+                    "type": "integer"
+                },
+                "content": {
+                    "type": "string"
+                },
+                "goodsId": {
+                    "type": "integer"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "star": {
+                    "type": "integer"
+                },
+                "time": {
+                    "type": "integer"
+                }
+            }
+        },
+        "model.AppraiseJson": {
+            "type": "object",
+            "properties": {
+                "buyerId": {
+                    "type": "integer"
+                },
+                "content": {
+                    "type": "string"
+                },
+                "goodsId": {
+                    "type": "integer"
+                },
+                "star": {
+                    "type": "integer"
+                },
+                "time": {
+                    "type": "integer"
+                }
+            }
+        },
+        "model.CategoryJson": {
+            "type": "object",
+            "properties": {
+                "name": {
+                    "type": "string"
+                },
+                "pic": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.Goods": {
+            "type": "object",
+            "properties": {
+                "desc": {
+                    "type": "string"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "integrity": {
+                    "type": "integer"
+                },
+                "ownerId": {
+                    "type": "integer"
+                },
+                "picId": {
+                    "type": "integer"
+                },
+                "place": {
+                    "type": "string"
+                },
+                "price": {
+                    "type": "integer"
+                },
+                "state": {
+                    "type": "integer"
+                },
+                "title": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.GoodsJson": {
+            "type": "object",
+            "properties": {
+                "categories": {
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
+                "desc": {
+                    "type": "string"
+                },
+                "integrity": {
+                    "type": "integer"
+                },
+                "ownerId": {
+                    "type": "integer"
+                },
+                "pic_id": {
+                    "type": "integer"
+                },
+                "place": {
+                    "type": "string"
+                },
+                "price": {
+                    "type": "integer"
+                },
+                "state": {
+                    "type": "integer"
+                },
+                "title": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.OrderJson": {
+            "type": "object",
+            "properties": {
+                "buyerId": {
+                    "type": "integer"
+                },
+                "goodsId": {
+                    "type": "integer"
+                },
+                "phone": {
+                    "type": "string"
+                },
+                "place": {
+                    "type": "string"
+                },
+                "state": {
+                    "type": "integer"
+                },
+                "time": {
+                    "type": "integer"
+                }
+            }
+        },
+        "model.RelationJson": {
+            "type": "object",
+            "properties": {
+                "owner": {
+                    "type": "integer"
+                },
+                "target": {
+                    "type": "integer"
+                },
+                "type": {
+                    "type": "integer"
+                }
+            }
+        },
+        "model.User": {
+            "type": "object",
+            "properties": {
+                "avatar": {
+                    "type": "string"
+                },
+                "name": {
+                    "type": "string"
+                },
+                "phone": {
+                    "type": "string"
+                },
+                "uid": {
+                    "type": "integer"
+                },
+                "vid": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.UserJson": {
+            "type": "object",
+            "properties": {
+                "avatar": {
+                    "type": "string"
+                },
+                "name": {
+                    "type": "string"
+                },
+                "phone": {
+                    "type": "string"
+                },
+                "vid": {
+                    "type": "string"
+                }
+            }
+        },
+        "response.Response": {
+            "type": "object",
+            "properties": {
+                "code": {
+                    "type": "integer"
+                },
+                "data": {},
+                "message": {
+                    "type": "string"
+                }
+            }
+        }
+    }
+}

+ 846 - 0
trading-go/bin/docs/swagger.yaml

@@ -0,0 +1,846 @@
+basePath: /WeChatTrading/trading-go
+definitions:
+  model.Appraise:
+    properties:
+      buyerId:
+        type: integer
+      content:
+        type: string
+      goodsId:
+        type: integer
+      id:
+        type: integer
+      star:
+        type: integer
+      time:
+        type: integer
+    type: object
+  model.AppraiseJson:
+    properties:
+      buyerId:
+        type: integer
+      content:
+        type: string
+      goodsId:
+        type: integer
+      star:
+        type: integer
+      time:
+        type: integer
+    type: object
+  model.CategoryJson:
+    properties:
+      name:
+        type: string
+      pic:
+        type: string
+    type: object
+  model.Goods:
+    properties:
+      desc:
+        type: string
+      id:
+        type: integer
+      integrity:
+        type: integer
+      ownerId:
+        type: integer
+      picId:
+        type: integer
+      place:
+        type: string
+      price:
+        type: integer
+      state:
+        type: integer
+      title:
+        type: string
+    type: object
+  model.GoodsJson:
+    properties:
+      categories:
+        items:
+          type: integer
+        type: array
+      desc:
+        type: string
+      integrity:
+        type: integer
+      ownerId:
+        type: integer
+      pic_id:
+        type: integer
+      place:
+        type: string
+      price:
+        type: integer
+      state:
+        type: integer
+      title:
+        type: string
+    type: object
+  model.OrderJson:
+    properties:
+      buyerId:
+        type: integer
+      goodsId:
+        type: integer
+      phone:
+        type: string
+      place:
+        type: string
+      state:
+        type: integer
+      time:
+        type: integer
+    type: object
+  model.RelationJson:
+    properties:
+      owner:
+        type: integer
+      target:
+        type: integer
+      type:
+        type: integer
+    type: object
+  model.User:
+    properties:
+      avatar:
+        type: string
+      name:
+        type: string
+      phone:
+        type: string
+      uid:
+        type: integer
+      vid:
+        type: string
+    type: object
+  model.UserJson:
+    properties:
+      avatar:
+        type: string
+      name:
+        type: string
+      phone:
+        type: string
+      vid:
+        type: string
+    type: object
+  response.Response:
+    properties:
+      code:
+        type: integer
+      data: {}
+      message:
+        type: string
+    type: object
+host: 127.0.0.1:8084
+info:
+  contact: {}
+  description: 一个基于微信小程序的校园二手交易平台的api文档
+  license:
+    name: Apache 2.0
+    url: http://www.apache.org/licenses/LICENSE-2.0.html
+  termsOfService: http://swagger.io/terms/
+  title: 二手交易
+  version: "1.0"
+paths:
+  /appraise/create:
+    post:
+      parameters:
+      - description: 评价信息
+        in: body
+        name: json
+        required: true
+        schema:
+          $ref: '#/definitions/model.AppraiseJson'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 创建评论
+      tags:
+      - 评论模块
+  /appraise/delete/{id}:
+    delete:
+      parameters:
+      - description: 评论id
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 删除评论
+      tags:
+      - 评论模块
+  /appraise/revise:
+    post:
+      parameters:
+      - description: 评价信息
+        in: body
+        name: json
+        required: true
+        schema:
+          $ref: '#/definitions/model.Appraise'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 修改评论
+      tags:
+      - 评论模块
+  /appraise/user:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取用户评价
+      tags:
+      - 评论模块
+  /category:
+    get:
+      consumes:
+      - application/json
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取所有分类
+      tags:
+      - 分类模块
+  /category/create:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 分类数据
+        in: body
+        name: json
+        required: true
+        schema:
+          $ref: '#/definitions/model.CategoryJson'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 创建分类
+      tags:
+      - 分类模块
+  /category/delete/{id}:
+    delete:
+      parameters:
+      - description: 分类id
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 根据分类id删除某个分类
+      tags:
+      - 分类模块
+  /chat:
+    get:
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 与服务端进行websocket连接,请使用postman测试
+      tags:
+      - 聊天模块
+  /chat/from:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: string
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取未过期且来源为特定用户的聊天记录
+      tags:
+      - 聊天模块
+  /chat/to:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: string
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取未过期且目标为特定用户的聊天记录
+      tags:
+      - 聊天模块
+  /goods/{page}/{pageSize}:
+    get:
+      parameters:
+      - description: 页数
+        in: path
+        name: page
+        required: true
+        type: integer
+      - description: 一页的大小
+        in: path
+        name: pageSize
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取所有商品
+      tags:
+      - 商品模块
+  /goods/category/{page}/{pageSize}:
+    get:
+      parameters:
+      - description: 页数
+        in: path
+        name: page
+        required: true
+        type: integer
+      - description: 一页的大小
+        in: path
+        name: pageSize
+        required: true
+        type: integer
+      - description: 商品分类id
+        in: query
+        name: category
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 按分类查找商品并分页显示
+      tags:
+      - 商品模块
+  /goods/create:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 商品信息
+        in: body
+        name: json
+        required: true
+        schema:
+          $ref: '#/definitions/model.GoodsJson'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 创建商品
+      tags:
+      - 商品模块
+  /goods/delete/{id}:
+    delete:
+      parameters:
+      - description: 商品id
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 删除商品
+      tags:
+      - 商品模块
+  /goods/detail/{id}:
+    get:
+      parameters:
+      - description: 商品id
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取商品详细信息
+      tags:
+      - 商品模块
+  /goods/recommend/{page}/{pageSize}:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: id
+        required: true
+        type: integer
+      - description: 页数
+        in: path
+        name: page
+        required: true
+        type: integer
+      - description: 一页的大小
+        in: path
+        name: pageSize
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 分页获取推荐商品
+      tags:
+      - 商品模块
+  /goods/revise:
+    post:
+      parameters:
+      - description: 商品信息
+        in: body
+        name: json
+        required: true
+        schema:
+          $ref: '#/definitions/model.Goods'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 修改商品信息
+      tags:
+      - 商品模块
+  /goods/search/{page}/{pageSize}:
+    get:
+      parameters:
+      - description: 页数
+        in: path
+        name: page
+        required: true
+        type: integer
+      - description: 一页的大小
+        in: path
+        name: pageSize
+        required: true
+        type: integer
+      - description: 搜素关键词
+        in: query
+        name: keyword
+        required: true
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 搜索商品并分页显示
+      tags:
+      - 商品模块
+  /goods/user/{id}:
+    get:
+      parameters:
+      - description: 用户id
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取某个用户的所有商品
+      tags:
+      - 商品模块
+  /message:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 传入用户id获取用户消息记录
+      tags:
+      - 信息模块
+  /message/conv:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: integer
+      - description: 对象id
+        in: query
+        name: targetId
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 传入用户id和聊天对象id获取消息记录
+      tags:
+      - 信息模块
+  /order:
+    get:
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取所有订单
+      tags:
+      - 订单模块
+  /order/create:
+    post:
+      parameters:
+      - description: 订单信息
+        in: body
+        name: json
+        required: true
+        schema:
+          $ref: '#/definitions/model.OrderJson'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 创建订单
+      tags:
+      - 订单模块
+  /order/delete/{id}:
+    delete:
+      parameters:
+      - description: 订单id
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 删除订单
+      tags:
+      - 订单模块
+  /order/revise:
+    post:
+      parameters:
+      - description: 订单id
+        in: formData
+        name: id
+        required: true
+        type: integer
+      - description: 订单状态
+        in: formData
+        name: state
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 修改订单的状态
+      tags:
+      - 订单模块
+  /order/user:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取用户的所有订单
+      tags:
+      - 订单模块
+  /pic:
+    get:
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取所有图片
+      tags:
+      - 图片模块
+  /pic/delete/{id}:
+    delete:
+      parameters:
+      - description: 图片id
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 删除图片
+      tags:
+      - 图片模块
+  /pic/upload:
+    post:
+      consumes:
+      - multipart/form-data
+      parameters:
+      - description: 图片
+        in: formData
+        name: pic
+        required: true
+        type: file
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 上传图片
+      tags:
+      - 图片模块
+  /relation/bad:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 传入用户id获取用户黑名单列表
+      tags:
+      - 用户关系模块
+  /relation/create:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 关系数据
+        in: body
+        name: json
+        required: true
+        schema:
+          $ref: '#/definitions/model.RelationJson'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 添加用户间的关系,关系类型有1:好友关系,2:黑名单关系
+      tags:
+      - 用户关系模块
+  /relation/delete/{id}:
+    delete:
+      parameters:
+      - description: 关系id
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 根据关系id删除关系
+      tags:
+      - 用户关系模块
+  /relation/friend:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 传入用户id获取用户好友列表
+      tags:
+      - 用户关系模块
+  /user/info:
+    get:
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取用户信息
+      tags:
+      - 用户模块
+  /user/login:
+    post:
+      parameters:
+      - description: 微信ID
+        in: formData
+        name: vid
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 登录
+      tags:
+      - 用户模块
+  /user/modify:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 用户信息
+        in: body
+        name: json
+        required: true
+        schema:
+          $ref: '#/definitions/model.User'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 修改用户信息
+      tags:
+      - 用户模块
+  /user/register:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 用户信息
+        in: body
+        name: json
+        required: true
+        schema:
+          $ref: '#/definitions/model.UserJson'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 创建用户
+      tags:
+      - 用户模块
+swagger: "2.0"

BIN
trading-go/bin/pic/1693216061Snipaste_2023-08-28_17-11-56.png


BIN
trading-go/bin/trading-go


+ 11 - 4
trading-go/common/database.go

@@ -2,12 +2,14 @@ package common
 
 import (
 	"fmt"
+	"github.com/go-redis/redis/v8"
 	_ "github.com/go-sql-driver/mysql"
 	"github.com/jmoiron/sqlx"
 	"github.com/spf13/viper"
 )
 
 var DB *sqlx.DB
+var Redis *redis.Client
 
 func initMySQL() {
 	host := viper.GetString("mysql.host")
@@ -23,7 +25,6 @@ func initMySQL() {
 		port,
 		database,
 		charset)
-	fmt.Println(dsn)
 	db, err := sqlx.Open("mysql", dsn)
 	if err != nil {
 		fmt.Printf("err:%#v", err)
@@ -34,6 +35,12 @@ func initMySQL() {
 	DB = db
 }
 
-//func initRedis() {
-//
-//}
+func initRedis() {
+	rdb := redis.NewClient(&redis.Options{
+		Addr:     viper.GetString("redis.addr"),
+		Password: viper.GetString("redis.password"),
+		DB:       viper.GetInt("redis.db"),
+		PoolSize: viper.GetInt("redis.poolsize"),
+	})
+	Redis = rdb
+}

+ 1 - 0
trading-go/common/init.go

@@ -3,4 +3,5 @@ package common
 func init() {
 	initConfig()
 	initMySQL()
+	initRedis()
 }

+ 69 - 0
trading-go/controller/chatcontroller.go

@@ -7,6 +7,7 @@ import (
 	"github.com/gorilla/websocket"
 	"net/http"
 	"strconv"
+	"time"
 	"trading-go/model"
 	"trading-go/response"
 )
@@ -35,6 +36,7 @@ func send(conn *websocket.Conn, uid uint) {
 	}()
 	for {
 		data := <-pip
+		data.Save()
 		msg, err := json.Marshal(data)
 		if err != nil {
 			fmt.Println("link closed")
@@ -60,6 +62,7 @@ func reception(conn *websocket.Conn, uid uint) {
 			fmt.Println(err.Error())
 			break
 		}
+		msg.Save()
 		if v, ok := Conns[msg.To]; ok {
 			v.pip <- &msg
 		} else {
@@ -83,6 +86,27 @@ func broadcast(data model.Message) {
 	}
 }
 
+func heartBeat(uid uint) {
+	defer func() {
+		delete(Conns, uid)
+	}()
+	for {
+		msg := model.Message{
+			MsgType: 4,
+			From:    0,
+			To:      uid,
+			Time:    uint(time.Now().Unix()),
+			Content: "alive",
+		}
+		if v, ok := Conns[msg.To]; ok {
+			v.pip <- &msg
+			time.Sleep(time.Second)
+		} else {
+
+		}
+	}
+}
+
 func Chat(w http.ResponseWriter, rq *http.Request, uid uint) {
 	// 升级为websocket
 	conn, err := UP.Upgrade(w, rq, nil)
@@ -101,6 +125,7 @@ func Chat(w http.ResponseWriter, rq *http.Request, uid uint) {
 
 	go send(conn, uid)
 	go reception(conn, uid)
+	go heartBeat(uid)
 
 	response.Success(w, "success", nil)
 }
@@ -118,3 +143,47 @@ func LinkToServer(c *gin.Context) {
 	}
 	Chat(c.Writer, c.Request, uint(uid))
 }
+
+// GetMsgFromPaged
+// @Tags 聊天模块
+// @Summary 获取未过期且来源为特定用户的聊天记录
+// @Success 200 {object} response.Response
+// @Param uid query string true "用户id"
+// @Router /chat/from [get]
+func GetMsgFromPaged(c *gin.Context) {
+	id := c.Query("uid")
+	uid, err := strconv.ParseUint(id, 10, 64)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	msgs, err := model.Message{}.GetFrom(uint(uid))
+	if err != nil {
+		response.Fail(c.Writer, err.Error(), 500)
+		return
+	}
+	response.Success(c.Writer, "success", msgs)
+}
+
+// GetMsgToPaged
+// @Tags 聊天模块
+// @Summary 获取未过期且目标为特定用户的聊天记录
+// @Success 200 {object} response.Response
+// @Param uid query string true "用户id"
+// @Router /chat/to [get]
+func GetMsgToPaged(c *gin.Context) {
+	id := c.Query("uid")
+	uid, err := strconv.ParseUint(id, 10, 64)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	msgs, err := model.Message{}.GetTo(uint(uid))
+	if err != nil {
+		response.Fail(c.Writer, err.Error(), 500)
+		return
+	}
+	response.Success(c.Writer, "success", msgs)
+}

+ 0 - 36
trading-go/controller/messagecontroller.go

@@ -1,36 +0,0 @@
-package controller
-
-import (
-	"github.com/gin-gonic/gin"
-	"trading-go/model"
-	"trading-go/response"
-)
-
-// History
-// @Tags 信息模块
-// @Summary 传入用户id获取用户消息记录
-// @Produce application/json
-// @Param uid query int64 true "用户id"
-// @Success 200 {object} response.Response
-// @Router /message [get]
-func History(c *gin.Context) {
-	var messages []model.Message
-	messages = append(messages, model.Message{})
-	messages = append(messages, model.Message{})
-	response.Success(c.Writer, "success", messages)
-}
-
-// ConversationHistory
-// @Tags 信息模块
-// @Summary 传入用户id和聊天对象id获取消息记录
-// @Produce application/json
-// @Param uid query int64 true "用户id"
-// @Param targetId query int64 true "对象id"
-// @Success 200 {object} response.Response
-// @Router /message/conv [get]
-func ConversationHistory(c *gin.Context) {
-	var messages []model.Message
-	messages = append(messages, model.Message{})
-	messages = append(messages, model.Message{})
-	response.Success(c.Writer, "success", messages)
-}

+ 51 - 64
trading-go/docs/docs.go

@@ -236,6 +236,56 @@ const docTemplate = `{
                 }
             }
         },
+        "/chat/from": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取未过期且来源为特定用户的聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat/to": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取未过期且目标为特定用户的聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/goods/category/{page}/{pageSize}": {
             "get": {
                 "produces": [
@@ -544,69 +594,6 @@ const docTemplate = `{
                 }
             }
         },
-        "/message": {
-            "get": {
-                "produces": [
-                    "application/json"
-                ],
-                "tags": [
-                    "信息模块"
-                ],
-                "summary": "传入用户id获取用户消息记录",
-                "parameters": [
-                    {
-                        "type": "integer",
-                        "description": "用户id",
-                        "name": "uid",
-                        "in": "query",
-                        "required": true
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "OK",
-                        "schema": {
-                            "$ref": "#/definitions/response.Response"
-                        }
-                    }
-                }
-            }
-        },
-        "/message/conv": {
-            "get": {
-                "produces": [
-                    "application/json"
-                ],
-                "tags": [
-                    "信息模块"
-                ],
-                "summary": "传入用户id和聊天对象id获取消息记录",
-                "parameters": [
-                    {
-                        "type": "integer",
-                        "description": "用户id",
-                        "name": "uid",
-                        "in": "query",
-                        "required": true
-                    },
-                    {
-                        "type": "integer",
-                        "description": "对象id",
-                        "name": "targetId",
-                        "in": "query",
-                        "required": true
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "OK",
-                        "schema": {
-                            "$ref": "#/definitions/response.Response"
-                        }
-                    }
-                }
-            }
-        },
         "/order": {
             "get": {
                 "produces": [
@@ -1269,7 +1256,7 @@ const docTemplate = `{
 // SwaggerInfo holds exported Swagger Info so clients can modify it
 var SwaggerInfo = &swag.Spec{
 	Version:          "1.0",
-	Host:             "127.0.0.1:8084",
+	Host:             "124.222.126.172:8084",
 	BasePath:         "/WeChatTrading/trading-go",
 	Schemes:          []string{},
 	Title:            "二手交易",

+ 51 - 64
trading-go/docs/swagger.json

@@ -11,7 +11,7 @@
         },
         "version": "1.0"
     },
-    "host": "127.0.0.1:8084",
+    "host": "124.222.126.172:8084",
     "basePath": "/WeChatTrading/trading-go",
     "paths": {
         "/appraise/create": {
@@ -229,6 +229,56 @@
                 }
             }
         },
+        "/chat/from": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取未过期且来源为特定用户的聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat/to": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取未过期且目标为特定用户的聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/goods/category/{page}/{pageSize}": {
             "get": {
                 "produces": [
@@ -537,69 +587,6 @@
                 }
             }
         },
-        "/message": {
-            "get": {
-                "produces": [
-                    "application/json"
-                ],
-                "tags": [
-                    "信息模块"
-                ],
-                "summary": "传入用户id获取用户消息记录",
-                "parameters": [
-                    {
-                        "type": "integer",
-                        "description": "用户id",
-                        "name": "uid",
-                        "in": "query",
-                        "required": true
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "OK",
-                        "schema": {
-                            "$ref": "#/definitions/response.Response"
-                        }
-                    }
-                }
-            }
-        },
-        "/message/conv": {
-            "get": {
-                "produces": [
-                    "application/json"
-                ],
-                "tags": [
-                    "信息模块"
-                ],
-                "summary": "传入用户id和聊天对象id获取消息记录",
-                "parameters": [
-                    {
-                        "type": "integer",
-                        "description": "用户id",
-                        "name": "uid",
-                        "in": "query",
-                        "required": true
-                    },
-                    {
-                        "type": "integer",
-                        "description": "对象id",
-                        "name": "targetId",
-                        "in": "query",
-                        "required": true
-                    }
-                ],
-                "responses": {
-                    "200": {
-                        "description": "OK",
-                        "schema": {
-                            "$ref": "#/definitions/response.Response"
-                        }
-                    }
-                }
-            }
-        },
         "/order": {
             "get": {
                 "produces": [

+ 33 - 42
trading-go/docs/swagger.yaml

@@ -135,7 +135,7 @@ definitions:
       message:
         type: string
     type: object
-host: 127.0.0.1:8084
+host: 124.222.126.172:8084
 info:
   contact: {}
   description: 一个基于微信小程序的校园二手交易平台的api文档
@@ -283,6 +283,38 @@ paths:
       summary: 与服务端进行websocket连接,请使用postman测试
       tags:
       - 聊天模块
+  /chat/from:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: string
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取未过期且来源为特定用户的聊天记录
+      tags:
+      - 聊天模块
+  /chat/to:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: string
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取未过期且目标为特定用户的聊天记录
+      tags:
+      - 聊天模块
   /goods/{page}/{pageSize}:
     get:
       parameters:
@@ -484,47 +516,6 @@ paths:
       summary: 获取某个用户的所有商品
       tags:
       - 商品模块
-  /message:
-    get:
-      parameters:
-      - description: 用户id
-        in: query
-        name: uid
-        required: true
-        type: integer
-      produces:
-      - application/json
-      responses:
-        "200":
-          description: OK
-          schema:
-            $ref: '#/definitions/response.Response'
-      summary: 传入用户id获取用户消息记录
-      tags:
-      - 信息模块
-  /message/conv:
-    get:
-      parameters:
-      - description: 用户id
-        in: query
-        name: uid
-        required: true
-        type: integer
-      - description: 对象id
-        in: query
-        name: targetId
-        required: true
-        type: integer
-      produces:
-      - application/json
-      responses:
-        "200":
-          description: OK
-          schema:
-            $ref: '#/definitions/response.Response'
-      summary: 传入用户id和聊天对象id获取消息记录
-      tags:
-      - 信息模块
   /order:
     get:
       produces:

+ 1 - 1
trading-go/main.go

@@ -14,7 +14,7 @@ import (
 // @license.name Apache 2.0
 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
 
-// @host 127.0.0.1:8084
+// @host 124.222.126.172:8084
 // @BasePath /WeChatTrading/trading-go
 func main() {
 	r := routine.GetRoutine()

+ 35 - 0
trading-go/model/message.go

@@ -1,5 +1,12 @@
 package model
 
+import (
+	"context"
+	"fmt"
+	"time"
+	"trading-go/common"
+)
+
 type Message struct {
 	MsgType int  `json:"msgType"`
 	From    uint `json:"from"`
@@ -7,3 +14,31 @@ type Message struct {
 	Time    uint `json:"time"`
 	Content any  `json:"content"`
 }
+
+func (m Message) Save() {
+	rds := common.Redis
+	ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
+	defer cancel()
+	key := fmt.Sprintf("%d:%d:%d", m.From, m.To, m.Time)
+	rds.Set(ctx, key, m, time.Second*60*60*24*30)
+}
+
+func (m Message) GetFrom(uid uint) (ms []Message, err error) {
+	rds := common.Redis
+	ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
+	defer cancel()
+	key := fmt.Sprintf("%d:*", uid)
+	result, err := rds.Do(ctx, "MGET", key).Result()
+	ms = result.([]Message)
+	return
+}
+
+func (m Message) GetTo(uid uint) (ms []Message, err error) {
+	rds := common.Redis
+	ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
+	defer cancel()
+	key := fmt.Sprintf("*:%d:*", uid)
+	result, err := rds.Do(ctx, "MGET", key).Result()
+	ms = result.([]Message)
+	return
+}

+ 6 - 8
trading-go/routine/routine.go

@@ -28,8 +28,12 @@ func GetRoutine() *gin.Engine {
 		user.POST("register", controller.Register)
 	}
 
-	r.GET("chat", controller.LinkToServer)
-
+	chat := r.Group("chat")
+	{
+		chat.GET("", controller.LinkToServer)
+		chat.GET("from", controller.GetMsgFromPaged)
+		chat.GET("to", controller.GetMsgToPaged)
+	}
 	relation := r.Group("relation")
 	{
 		relation.POST("create", controller.RCreat)
@@ -38,12 +42,6 @@ func GetRoutine() *gin.Engine {
 		relation.DELETE("delete/:id", controller.DRelation)
 	}
 
-	message := r.Group("message")
-	{
-		message.GET("", controller.History)
-		message.GET("conv", controller.ConversationHistory)
-	}
-
 	category := r.Group("category")
 	{
 		category.GET("", controller.GetAllCategories)