feat: export function printTree
we can do more thing with an exported PrintTree function, such as set role base access control,create our own requests statistics.
This commit is contained in:
		
							parent
							
								
									3c0c87f473
								
							
						
					
					
						commit
						b9e3cbbf44
					
				
							
								
								
									
										49
									
								
								admin.go
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								admin.go
									
									
									
									
									
								
							| @ -105,29 +105,12 @@ func listConf(rw http.ResponseWriter, r *http.Request) { | |||||||
| 		tmpl.Execute(rw, data) | 		tmpl.Execute(rw, data) | ||||||
| 
 | 
 | ||||||
| 	case "router": | 	case "router": | ||||||
| 		var ( | 		content := PrintTree() | ||||||
| 			content = map[string]interface{}{ | 		content["Fields"] = []string{ | ||||||
| 				"Fields": []string{ | 			"Router Pattern", | ||||||
| 					"Router Pattern", | 			"Methods", | ||||||
| 					"Methods", | 			"Controller", | ||||||
| 					"Controller", |  | ||||||
| 				}, |  | ||||||
| 			} |  | ||||||
| 			methods     = []string{} |  | ||||||
| 			methodsData = make(map[string]interface{}) |  | ||||||
| 		) |  | ||||||
| 		for method, t := range BeeApp.Handlers.routers { |  | ||||||
| 
 |  | ||||||
| 			resultList := new([][]string) |  | ||||||
| 
 |  | ||||||
| 			printTree(resultList, t) |  | ||||||
| 
 |  | ||||||
| 			methods = append(methods, method) |  | ||||||
| 			methodsData[method] = resultList |  | ||||||
| 		} | 		} | ||||||
| 
 |  | ||||||
| 		content["Data"] = methodsData |  | ||||||
| 		content["Methods"] = methods |  | ||||||
| 		data["Content"] = content | 		data["Content"] = content | ||||||
| 		data["Title"] = "Routers" | 		data["Title"] = "Routers" | ||||||
| 		execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl) | 		execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl) | ||||||
| @ -200,6 +183,28 @@ func list(root string, p interface{}, m map[string]interface{}) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // PrintTree prints all registered routers. | ||||||
|  | func PrintTree() map[string]interface{} { | ||||||
|  | 	var ( | ||||||
|  | 		content     = map[string]interface{}{} | ||||||
|  | 		methods     = []string{} | ||||||
|  | 		methodsData = make(map[string]interface{}) | ||||||
|  | 	) | ||||||
|  | 	for method, t := range BeeApp.Handlers.routers { | ||||||
|  | 
 | ||||||
|  | 		resultList := new([][]string) | ||||||
|  | 
 | ||||||
|  | 		printTree(resultList, t) | ||||||
|  | 
 | ||||||
|  | 		methods = append(methods, method) | ||||||
|  | 		methodsData[method] = resultList | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	content["Data"] = methodsData | ||||||
|  | 	content["Methods"] = methods | ||||||
|  | 	return content | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func printTree(resultList *[][]string, t *Tree) { | func printTree(resultList *[][]string, t *Tree) { | ||||||
| 	for _, tr := range t.fixrouters { | 	for _, tr := range t.fixrouters { | ||||||
| 		printTree(resultList, tr) | 		printTree(resultList, tr) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user