Skip to content

Commit

Permalink
增加系统开启关闭接口
Browse files Browse the repository at this point in the history
  • Loading branch information
tongsq committed Jun 23, 2024
1 parent 45eb7ad commit 327c996
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions bootstrap/servers/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func StartApiServer() {
})
})
router.GET("/all", func(c *gin.Context) {
if !config.SystemStart {
c.JSON(403, gin.H{
"code": 403,
"msg": "System not start",
})
return
}
proxies, err := dao.ProxyDao.GetActiveList()
if err != nil {
logger.Error("get active proxy fail", logger.Fields{"err": err})
Expand Down Expand Up @@ -75,6 +82,18 @@ func StartApiServer() {
"count": len(list),
})
})
router.GET("/start", func(c *gin.Context) {
config.SystemStart = true
c.JSON(200, gin.H{
"message": "success",
})
})
router.GET("/stop", func(c *gin.Context) {
config.SystemStart = false
c.JSON(200, gin.H{
"message": "success",
})
})
err := r.Run(fmt.Sprintf("%s:%s", config.Get().Api.Host, config.Get().Api.Port))
if err != nil {
panic("start api server fail:" + err.Error())
Expand Down
1 change: 1 addition & 0 deletions config/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
var conf *ConfDto
var YamlPath = "conf.yaml"
var configRefreshHandlers []func(old, new *ConfDto)
var SystemStart = true

func Get() *ConfDto {
if conf == nil {
Expand Down
4 changes: 4 additions & 0 deletions scheduler/get_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type GetIp struct {

func (s GetIp) Run() {
logger.FSuccess("collect ip start run")
if !config.SystemStart {
logger.Info("system not start", map[string]interface{}{})
return
}
//pool := component.NewTaskPool(100)
//defer pool.Close()
serviceList := []service.ProxyGetterInterface{
Expand Down

0 comments on commit 327c996

Please sign in to comment.