github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/debug/debug_api.go (about)

     1  package debug
     2  
     3  import (
     4  	"github.com/gin-gonic/gin"
     5  	"github.com/isyscore/isc-gobase/config"
     6  	"github.com/isyscore/isc-gobase/isc"
     7  	"github.com/isyscore/isc-gobase/server/rsp"
     8  	"strings"
     9  )
    10  
    11  func Help(c *gin.Context) {
    12  	port := config.GetValueIntDefault("base.server.port", 8080)
    13  	cmdMap := map[string]any{}
    14  	cmdMap["-============================================================================================================================================================================================"] = ""
    15  	cmdMap["1.-【帮助】"] = "---------------------: " + "curl http://localhost:" + pre(port) + "/debug/help"
    16  	cmdMap["2.-"] = "========================【日志】==========================================================================================================================================================="
    17  	cmdMap["2.1 动态修改日志"] = "-----------------: " + "curl -X PUT http://localhost:" + pre(port) + "/config/update -d '{\"key\":\"base.logger.level\", \"value\":\"debug\"}'"
    18  	cmdMap["3.-"] = "===================【接口出入参】==========================================================================================================================================================="
    19  	cmdMap["3.1 指定url打印请求"] = "--------------: " + "curl -X PUT http://localhost:" + pre(port) + "/config/update -d '{\"key\":\"base.server.request.print.include-uri[0]\", \"value\":\"/api/xx/xxx\"}'"
    20  	cmdMap["3.2 指定url不打印请求"] = "------------: " + "curl -X PUT http://localhost:" + pre(port) + "/config/update -d '{\"key\":\"base.server.request.print.exclude-uri[0]\", \"value\":\"/api/xx/xxx\"}'"
    21  	cmdMap["3.3 指定url打印请求和响应"] = "---------: " + "curl -X PUT http://localhost:" + pre(port) + "/config/update -d '{\"key\":\"base.server.response.print.include-uri[0]\", \"value\":\"/api/xx/xxx\"}'"
    22  	cmdMap["3.4 指定url不打印请求和响应"] = "-------: " + "curl -X PUT http://localhost:" + pre(port) + "/config/update -d '{\"key\":\"base.server.response.print.exclude-uri[0]\", \"value\":\"/api/xx/xxx\"}'"
    23  	cmdMap["4.-"] = "===================【bean管理】============================================================================================================================================================"
    24  	cmdMap["4.1 获取注册的所有bean"] = "-----------: " + "curl http://localhost:" + pre(port) + "/bean/name/all"
    25  	cmdMap["4.2 查询注册的bean"] = "--------------: " + "curl http://localhost:" + pre(port) + "/bean/name/list/{name}"
    26  	cmdMap["4.3 查询bean的属性值"] = "-------------: " + "curl -X POST http://localhost:" + pre(port) + "/bean/field/get' -d '{\"bean\": \"xx\", \"field\":\"xxx\"}'"
    27  	cmdMap["4.4 修改bean的属性值"] = "-------------: " + "curl -X POST http://localhost:" + pre(port) + "/bean/field/set' -d '{\"bean\": \"xx\", \"field\": \"xxx\", \"value\": \"xxx\"}'"
    28  	cmdMap["4.5 调用bean的函数"] = "--------------: " + "curl -X POST http://localhost:" + pre(port) + "/bean/fun/call' -d '{\"bean\": \"xx\", \"fun\": \"xxx\", \"parameter\": {\"p1\":\"xx\", \"p2\": \"xxx\"}}'"
    29  	cmdMap["5.-"] = "=====================【pprof】============================================================================================================================================================"
    30  	cmdMap["5.1 动态启用pprof"] = "---------------: " + "curl -X PUT http://localhost:" + pre(port) + "/config/update -d '{\"key\":\"base.server.gin.pprof.enable\", \"value\":\"true\"}'"
    31  	cmdMap["6.-"] = "===================【配置处理】============================================================================================================================================================="
    32  	cmdMap["6.1 服务所有配置"] = "----------------: " + "curl http://localhost:" + pre(port) + "/config/values"
    33  	cmdMap["6.2 服务所有配置(yaml结构)"] = "-------: " + "curl http://localhost:" + pre(port) + "/config/values/yaml"
    34  	cmdMap["6.3 服务某个配置"] = "----------------: " + "curl http://localhost:" + pre(port) + "/config/value/{key}"
    35  	cmdMap["6.4 修改服务的配置"] = "--------------: " + "curl -X PUT http://localhost:" + pre(port) + "/config/update -d '{\"key\":\"xxx\", \"value\":\"yyy\"}'"
    36  	cmdMap["==============================================================================================================================================================================================="] = ""
    37  
    38  	rsp.Success(c, cmdMap)
    39  }
    40  
    41  func pre(port int) string {
    42  	return isc.ToString(port) + apiPreAndModule()
    43  }
    44  
    45  func apiPreAndModule() string {
    46  	apiPrefix := config.GetValueStringDefault("base.api.prefix", "/api")
    47  	apiPrefix = strings.TrimSuffix(apiPrefix, "/")
    48  	module := strings.Trim(config.ApiModule, "/")
    49  
    50  	if !strings.HasPrefix(apiPrefix, "/") {
    51  		apiPrefix = "/" + apiPrefix
    52  	}
    53  
    54  	if module == "" {
    55  		return apiPrefix
    56  	}
    57  
    58  	return apiPrefix + "/" + module
    59  }