Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DbChainCmd *cobra.Command = &cobra.Command{ Use: "dc", Short: "database call chain grpah", Long: ``, Run: func(cmd *cobra.Command, args []string) { source := cmd.Flag("source").Value.String() point := cmd.Flag("point").Value.String() codeFiles := make([]string, 0) filepath.Walk(source, func(path string, fi os.FileInfo, err error) error { codeFiles = append(codeFiles, path) return nil }) allP := parseAllPkg(codeFiles) pTree, pTables := allP.Print(point) tables := make([]string, 0) for key, rw := range pTables { tables = append(tables, fmt.Sprintf("%s [%s]", key, rw.ToString())) } sort.Slice(tables, func(i, j int) bool { return strings.Compare(tables[i], tables[j]) < 0 }) for _, t := range tables { fmt.Printf("%s\n", t) } graph := gographviz.NewGraph() graph.SetName("G") nodeIndex := 1 nodes := make(map[string]string) for key := range pTree { tmp := strings.Split(key, " -> ") if cmd.Flag("mergePackage").Value.String() == "true" { nodes[strings.Split(tmp[0], ".")[0]] = "" nodes[strings.Split(tmp[1], ".")[0]] = "" } else { nodes[tmp[0]] = "" nodes[tmp[1]] = "" } } owner := cmd.Flag("key").Value.String() for node := range nodes { attrs := make(map[string]string) attrs["label"] = "\"" + node + "\"" attrs["shape"] = "box" if owner != "" { if strings.Contains(node, owner) { attrs["color"] = "greenyellow" attrs["style"] = "filled" } else { attrs["color"] = "orange" attrs["style"] = "filled" } } graph.AddNode("G", "node"+strconv.Itoa(nodeIndex), attrs) nodes[node] = "node" + strconv.Itoa(nodeIndex) nodeIndex++ } relations := make(map[string]string) for key := range pTree { attrs := make(map[string]string) tmp := strings.Split(key, " -> ") if cmd.Flag("mergePackage").Value.String() == "true" { pName0 := strings.Split(tmp[0], ".")[0] pName1 := strings.Split(tmp[1], ".")[0] if pName0 != pName1 { if _, ok := relations[pName0+pName1]; !ok { relations[pName0+pName1] = "" graph.AddEdge(nodes[pName0], nodes[pName1], true, attrs) } } } else { graph.AddEdge(nodes[tmp[0]], nodes[tmp[1]], true, attrs) } } f, _ := os.Create(cmd.Flag("output").Value.String()) w := bufio.NewWriter(f) w.WriteString("di" + graph.String()) w.Flush() }, }
Functions ¶
func BytesCombine ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.