package controllers import ( "fmt" "github.com/gin-gonic/gin" "strings" "swfs/code" "swfs/config" "swfs/tools/es" "swfs/tools/middleware" "swfs/tools/script" "swfs/util" "time" ) type SeaweedfsController struct{} type SWFSInfo struct { Role string `json:"role"` } func (sc *SeaweedfsController) UpdateSWFSServiceController(c *gin.Context) { script.ReplaceLineContentBySearch(es.GetNewPeers(), config.Peer, config.Server.ScriptPath, config.StartServerScript) util.ResponseFormat(c, code.Success, config.Server.EsServerIp+"更新成功") } // @Security ApiKeyAuth // @Summary 新节点加入 // @Description 新节点加入 // @Accept json // @Produce json // @Tags swfs // @Param obj body SWFSInfo true "加入角色参数" // @Success 200 {string} json "{"code":200, msg:"", success:true}" // @Failure 500 {string} json "{"code":500, msg:"", success:false}" // @Router /node/api-v/swfs/addSWFSNode [POST] func (sc *SeaweedfsController) AddSWFSNodeController(c *gin.Context) { var body SWFSInfo c.BindJSON(&body) role := body.Role if role == "master" { middleware.AsMaster(role) util.ResponseFormat(c, code.AddSuccess, "加入节点成功") return } else if role == "volume" { status := middleware.AsVolume() if status == true { util.ResponseFormat(c, code.AddSuccess, "加入节点成功") return } else { util.ResponseFormat(c, code.AddClusterInfoErr, "当前还没有主节点") return } } else if role == "master+volume" { middleware.AsMaVo(role) util.ResponseFormat(c, code.AddSuccess, "加入节点成功") } else { util.ResponseFormat(c, code.RequestParamError, "选择节点类型错误") return } } func (sc *SeaweedfsController) RoleOfVolumeToMasterController(c *gin.Context) { middleware.AsMaster("master+volume") util.ResponseFormat(c, code.Success, "角色添加成功") } func (sc *SeaweedfsController) RestartServerController(c *gin.Context) { script.StopServer(config.Server.ScriptPath) script.StartServer(config.Server.ScriptPath) time.Sleep(time.Second * 1) //fmt.Println("GetLocalStartupItem: ", GetLocalStartupItem(config.Server.ScriptPath, StartServerScript)) result := strings.Split(middleware.GetLocalStartupItem(config.Server.ScriptPath, config.StartServerScript), "=")[1] fmt.Println("result: ", result) util.ResponseFormat(c, code.Success, result) }