From ea7b2be0141ff073c97730831cc7fb0300b79b08 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 17 Dec 2019 08:05:40 +0800 Subject: [PATCH] refactor: move http method out api model --- cmd/api.go | 5 ++--- src/domain/call_graph.go | 9 ++++----- src/domain/call_model.go | 7 ++++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/api.go b/cmd/api.go index a024c19..ccb28e2 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -53,10 +53,10 @@ var apiCmd *cobra.Command = &cobra.Command{ if apiCmdConfig.ShowCount { table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Size", "API", "Caller"}) + table.SetHeader([]string{"Size", "Method", "Uri", "Caller"}) for _, v := range counts { - table.Append([]string{strconv.Itoa(v.Size), v.ApiName, replacePackage(v.Caller)}) + table.Append([]string{strconv.Itoa(v.Size), v.HttpMethod, v.Uri, replacePackage(v.Caller)}) } table.Render() } @@ -90,7 +90,6 @@ func replacePackage(content string) string { return re.ReplaceAllString(content, "") - //return strings.ReplaceAll(content, apiCmdConfig.RemovePackageNames, "") } func init() { diff --git a/src/domain/call_graph.go b/src/domain/call_graph.go index 9c8fa83..22e07e4 100644 --- a/src/domain/call_graph.go +++ b/src/domain/call_graph.go @@ -52,7 +52,6 @@ func BuildCallChain(funcName string, methodMap map[string][]string) string { return "\n" } - func (c CallGraph) AnalysisByFiles(restApis []api.RestApi, deps []models.JClassNode) (string, []CallApiCount) { methodMap := c.BuildMethodMap(deps) var apiCallSCounts []CallApiCount @@ -68,9 +67,10 @@ func (c CallGraph) AnalysisByFiles(restApis []api.RestApi, deps []models.JClassN chain = chain + apiCallChain count := &CallApiCount{ - Caller: caller, - ApiName: restApi.HttpMethod + " " + restApi.Uri, - Size: len(strings.Split(apiCallChain, " -> ")), + HttpMethod: restApi.HttpMethod, + Caller: caller, + Uri: restApi.Uri, + Size: len(strings.Split(apiCallChain, " -> ")), } apiCallSCounts = append(apiCallSCounts, *count) @@ -101,4 +101,3 @@ func (c CallGraph) BuildMethodMap(clzs []models.JClassNode) map[string][]string return methodMap } - diff --git a/src/domain/call_model.go b/src/domain/call_model.go index 1fa7bb2..cb82fd3 100644 --- a/src/domain/call_model.go +++ b/src/domain/call_model.go @@ -1,7 +1,8 @@ package domain type CallApiCount struct { - Caller string - ApiName string - Size int + HttpMethod string + Uri string + Caller string + Size int } -- GitLab