From b0500fee9c01e17c81b9293b244c8ed88dc9ca29 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期五, 11 十月 2019 15:12:25 +0800 Subject: [PATCH] add swagger --- controllers/cluster.go | 86 ++++++++++++++++++++++++++++++++++++++---- 1 files changed, 77 insertions(+), 9 deletions(-) diff --git a/controllers/cluster.go b/controllers/cluster.go index 4d844ee..749d249 100644 --- a/controllers/cluster.go +++ b/controllers/cluster.go @@ -2,7 +2,10 @@ import ( "basic.com/dbapi.git" + "fmt" "github.com/gin-gonic/gin" + "math/rand" + "time" "webserver/extend/code" "webserver/extend/util" ) @@ -37,6 +40,7 @@ Password string `json:"password"` ClusterName string `json:"clusterName"` ClusterId string `json:"clusterId"` + VirtualIp string `json:"virtualIp"` } type ClusterSearchVo struct { @@ -67,11 +71,40 @@ return } var api dbapi.ClusterApi - b, d := api.Create(clusterVo.ClusterName, clusterVo.Password) + b, d := api.Create(clusterVo.ClusterName, clusterVo.Password, clusterVo.VirtualIp) if b { util.ResponseFormat(c,code.Success, d) } else { util.ResponseFormat(c,code.ComError,"鍒涘缓澶辫触") + } +} + +// @Summary 鐢熸垚闆嗙兢6浣嶉殢鏈哄瘑鐮� +// @Description 鐢熸垚闆嗙兢6浣嶉殢鏈哄瘑鐮� +// @Produce json +// @Tags cluster +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" +// @Router /data/api-v/cluster/randomPwd [get] +func (cc ClusterController) RandomPwd(c *gin.Context) { + pwd := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000)) + util.ResponseFormat(c,code.Success,pwd) +} + +// @Summary 鏌ヨ鏈湴闆嗙兢 +// @Description 鏌ヨ鏈湴闆嗙兢 +// @Produce json +// @Tags cluster +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" +// @Router /data/api-v/cluster/findCluster [get] +func (cc ClusterController) FindCluster(c *gin.Context) { + var clusterApi dbapi.ClusterApi + b, d := clusterApi.FindCluster() + if b { + util.ResponseFormat(c,code.Success, d) + } else { + util.ResponseFormat(c,code.ComError,"闆嗙兢鏌ヨ澶辫触") } } @@ -122,18 +155,12 @@ // @Description 閫氳繃searchNum鍋滄鎼滅储 // @Produce json // @Tags cluster -// @Param searchNum query string true "鎼滅储缂栧彿" // @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" // @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" // @Router /data/api-v/cluster/stopSearching [post] func (cc ClusterController) StopSearching(c *gin.Context) { - searchNum := c.Query("searchNum") - if searchNum == "" { - util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎") - return - } var api dbapi.ClusterApi - b, d := api.StopSearching(searchNum) + b, d := api.StopSearching("") if b { util.ResponseFormat(c,code.Success, d) } else { @@ -147,7 +174,7 @@ // @Accept json // @Produce json // @Tags cluster -// @Param clusterArg body controllers.ClusterCreateVo true "闆嗙兢鍒涘缓鍙傛暟" +// @Param clusterArg body controllers.ClusterJoinVo true "闆嗙兢鍒涘缓鍙傛暟" // @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" // @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" // @Router /data/api-v/cluster/joinCluster [post] @@ -167,3 +194,44 @@ util.ResponseFormat(c,code.ComError,"鍔犲叆澶辫触") } } + +// @Summary 淇濆瓨闆嗙兢鍚嶇О +// @Description 淇濆瓨闆嗙兢鍚嶇О +// @Produce json +// @Tags cluster +// @Param clusterName formData string true "闆嗙兢鍚嶇О" +// @Param virtualIp formData string false "铏氭嫙ip" +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" +// @Router /data/api-v/cluster/updateClusterName [post] +func (cc ClusterController) UpdateClusterName(c *gin.Context) { + clusterName := c.PostForm("clusterName") + if clusterName == "" { + util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎") + return + } + virtualIp := c.PostForm("virtualIp") + var api dbapi.ClusterApi + b,_ := api.UpdateClusterName(clusterName,virtualIp) + if b { + util.ResponseFormat(c,code.UpdateSuccess,"鏇存柊鎴愬姛") + } else { + util.ResponseFormat(c,code.ComError, "鏇存柊澶辫触") + } +} + +// @Summary 閫�鍑洪泦缇� +// @Description 閫�鍑洪泦缇� +// @Produce json +// @Tags cluster +// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" +// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" +// @Router /data/api-v/cluster/leave [post] +func (cc ClusterController) Leave(c *gin.Context) { + var api dbapi.ClusterApi + if b,_:= api.Leave();b { + util.ResponseFormat(c,code.Success,"閫�鍑烘垚鍔�") + } else { + util.ResponseFormat(c,code.ComError,"閫�鍑哄け璐�") + } +} \ No newline at end of file -- Gitblit v1.8.0