diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-03-26 19:42:52 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-03-26 19:42:52 -0600 |
commit | a8dc73b4d9db5edf85e78314c9759b9d12a79b71 (patch) | |
tree | c1283aa94e2b2d605985130cdef070a24d03815e /caddy.go | |
parent | 86e2d1b0a48fbd84590291969611f1870471c3e0 (diff) |
Performance testing Load function
Diffstat (limited to 'caddy.go')
-rw-r--r-- | caddy.go | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -3,10 +3,16 @@ package caddy2 import ( "encoding/json" "fmt" + "log" + "runtime/debug" "strings" + "sync" "time" ) +var currentCfg *Config +var currentCfgMu sync.Mutex + // Start runs Caddy with the given config. func Start(cfg Config) error { cfg.runners = make(map[string]Runner) @@ -26,16 +32,33 @@ func Start(cfg Config) error { for name, r := range cfg.runners { err := r.Run() if err != nil { + // TODO: If any one has an error, stop the others return fmt.Errorf("%s module: %v", name, err) } } + currentCfgMu.Lock() + if currentCfg != nil { + for _, r := range cfg.runners { + err := r.Cancel() + if err != nil { + log.Println(err) + } + } + } + currentCfg = &cfg + currentCfgMu.Unlock() + + // TODO: debugging memory leak... + debug.FreeOSMemory() + return nil } // Runner is a thing that Caddy runs. type Runner interface { Run() error + Cancel() error } // Config represents a Caddy configuration. |