mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 03:27:23 -05:00 
			
		
		
		
	Merge pull request #250 from hacdias/master
browse: User defined variables (for templates)
This commit is contained in:
		
						commit
						540a651fdf
					
				@ -32,6 +32,7 @@ type Browse struct {
 | 
				
			|||||||
// Config is a configuration for browsing in a particular path.
 | 
					// Config is a configuration for browsing in a particular path.
 | 
				
			||||||
type Config struct {
 | 
					type Config struct {
 | 
				
			||||||
	PathScope string
 | 
						PathScope string
 | 
				
			||||||
 | 
						Variables interface{}
 | 
				
			||||||
	Template  *template.Template
 | 
						Template  *template.Template
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -55,6 +56,9 @@ type Listing struct {
 | 
				
			|||||||
	// And which order
 | 
						// And which order
 | 
				
			||||||
	Order string
 | 
						Order string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// User defined costum variables
 | 
				
			||||||
 | 
						User interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	middleware.Context
 | 
						middleware.Context
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -143,7 +147,7 @@ var IndexPages = []string{
 | 
				
			|||||||
	"default.txt",
 | 
						"default.txt",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func directoryListing(files []os.FileInfo, r *http.Request, canGoUp bool, root string, ignoreIndexes bool) (Listing, error) {
 | 
					func directoryListing(files []os.FileInfo, r *http.Request, canGoUp bool, root string, ignoreIndexes bool, vars interface{}) (Listing, error) {
 | 
				
			||||||
	var fileinfos []FileInfo
 | 
						var fileinfos []FileInfo
 | 
				
			||||||
	var urlPath = r.URL.Path
 | 
						var urlPath = r.URL.Path
 | 
				
			||||||
	for _, f := range files {
 | 
						for _, f := range files {
 | 
				
			||||||
@ -184,6 +188,7 @@ func directoryListing(files []os.FileInfo, r *http.Request, canGoUp bool, root s
 | 
				
			|||||||
			Req:  r,
 | 
								Req:  r,
 | 
				
			||||||
			URL:  r.URL,
 | 
								URL:  r.URL,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							User: vars,
 | 
				
			||||||
	}, nil
 | 
						}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -237,7 +242,7 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// Assemble listing of directory contents
 | 
							// Assemble listing of directory contents
 | 
				
			||||||
		listing, err := directoryListing(files, r, canGoUp, b.Root, b.IgnoreIndexes)
 | 
							listing, err := directoryListing(files, r, canGoUp, b.Root, b.IgnoreIndexes, bc.Variables)
 | 
				
			||||||
		if err != nil { // directory isn't browsable
 | 
							if err != nil { // directory isn't browsable
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user