mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-30 18:22:49 -04:00 
			
		
		
		
	First use of OncePerServerBlock in a Setup function
startup and shutdown commands should only be executed once per appearance in the Caddyfile (naturally meaning once per server block). Notice that we support multiple occurrences of startup and shutdown in the same server block by building the callback array incrementally as we parse the Caddyfile, then we append all the callbacks all at once. Quite literally, the OncePerServerBlock function executes only once per server block!
This commit is contained in:
		
							parent
							
								
									e0fdddc73f
								
							
						
					
					
						commit
						35e309cf87
					
				| @ -20,6 +20,8 @@ func Shutdown(c *Controller) (middleware.Middleware, error) { | ||||
| // using c to parse the line. It appends the callback function | ||||
| // to the list of callback functions passed in by reference. | ||||
| func registerCallback(c *Controller, list *[]func() error) error { | ||||
| 	var funcs []func() error | ||||
| 
 | ||||
| 	for c.Next() { | ||||
| 		args := c.RemainingArgs() | ||||
| 		if len(args) == 0 { | ||||
| @ -50,8 +52,12 @@ func registerCallback(c *Controller, list *[]func() error) error { | ||||
| 			return cmd.Run() | ||||
| 		} | ||||
| 
 | ||||
| 		*list = append(*list, fn) | ||||
| 		funcs = append(funcs, fn) | ||||
| 	} | ||||
| 
 | ||||
| 	c.OncePerServerBlock(func() { | ||||
| 		*list = append(*list, funcs...) | ||||
| 	}) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user