Add random delay and errors middleware

This commit is contained in:
Stefan Prodan
2018-08-21 03:12:20 +03:00
parent 0f098cf0f1
commit 593ccaa0cd
4 changed files with 39 additions and 2 deletions
+8
View File
@@ -34,6 +34,8 @@ type Config struct {
ConfigPath string `mapstructure:"config-path"`
Port string `mapstructure:"port"`
Hostname string `mapstructure:"hostname"`
RandomDelay bool `mapstructure:"random-delay"`
RandomError bool `mapstructure:"random-error"`
}
type Server struct {
@@ -80,6 +82,12 @@ func (s *Server) registerMiddlewares() {
httpLogger := NewLoggingMiddleware(s.logger)
s.router.Use(httpLogger.Handler)
s.router.Use(versionMiddleware)
if s.config.RandomDelay {
s.router.Use(randomDelayMiddleware)
}
if s.config.RandomError {
s.router.Use(randomErrorMiddleware)
}
}
func (s *Server) ListenAndServe(stopCh <-chan struct{}) {