Template debugging
This commit is contained in:
		
							
								
								
									
										18
									
								
								debug.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								debug.go
									
									
									
									
									
								
							@ -4,7 +4,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package gin
 | 
					package gin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "log"
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"html/template"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	log.SetFlags(0)
 | 
						log.SetFlags(0)
 | 
				
			||||||
@ -24,6 +28,18 @@ func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func debugPrintLoadTemplate(tmpl *template.Template) {
 | 
				
			||||||
 | 
						if IsDebugging() {
 | 
				
			||||||
 | 
							var buf bytes.Buffer
 | 
				
			||||||
 | 
							for _, tmpl := range tmpl.Templates() {
 | 
				
			||||||
 | 
								buf.WriteString("\t- ")
 | 
				
			||||||
 | 
								buf.WriteString(tmpl.Name())
 | 
				
			||||||
 | 
								buf.WriteString("\n")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func debugPrint(format string, values ...interface{}) {
 | 
					func debugPrint(format string, values ...interface{}) {
 | 
				
			||||||
	if IsDebugging() {
 | 
						if IsDebugging() {
 | 
				
			||||||
		log.Printf("[GIN-debug] "+format, values...)
 | 
							log.Printf("[GIN-debug] "+format, values...)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								gin.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								gin.go
									
									
									
									
									
								
							@ -123,6 +123,7 @@ func (engine *Engine) allocateContext() *Context {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (engine *Engine) LoadHTMLGlob(pattern string) {
 | 
					func (engine *Engine) LoadHTMLGlob(pattern string) {
 | 
				
			||||||
	if IsDebugging() {
 | 
						if IsDebugging() {
 | 
				
			||||||
 | 
							debugPrintLoadTemplate(template.Must(template.ParseGlob(pattern)))
 | 
				
			||||||
		engine.HTMLRender = render.HTMLDebug{Glob: pattern}
 | 
							engine.HTMLRender = render.HTMLDebug{Glob: pattern}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		templ := template.Must(template.ParseGlob(pattern))
 | 
							templ := template.Must(template.ParseGlob(pattern))
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user