dsl/pact.go
func stateHandlerMiddleware(stateHandlers types.StateHandlers) proxy.Middleware {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if r.URL.Path == "/__setup" {
				var s *types.ProviderState
				decoder := json.NewDecoder(r.Body)
				decoder.Decode(&s)

				// Setup any provider state
				for _, state := range s.States {
					sf, stateFound := stateHandlers[state]

					if !stateFound {
						log.Printf("[WARN] state handler not found for state: %v", state)
					} else {
						// Execute state handler
						if err := sf(); err != nil {
							log.Printf("[ERROR] state handler for '%v' errored: %v", state, err)
							w.WriteHeader(http.StatusInternalServerError)
							return
						}
					}
				}

				w.WriteHeader(http.StatusOK)
				return
			}

			log.Println("[DEBUG] skipping state handler for request", r.RequestURI)

			// Pass through to application
			next.ServeHTTP(w, r)
		})
	}
}
func stateHandlerMiddleware(stateHandlers types.StateHandlers) proxy.Middleware {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if r.URL.Path == "/__setup" {
				var s *types.ProviderState
				decoder := json.NewDecoder(r.Body)
				decoder.Decode(&s)

				// Setup any provider state
				for _, state := range s.States {
					sf, stateFound := stateHandlers[state]

					if !stateFound {
						log.Printf("[WARN] state handler not found for state: %v", state)
					} else {
						// Execute state handler
						if err := sf(); err != nil {
							log.Printf("[ERROR] state handler for '%v' errored: %v", state, err)
							w.WriteHeader(http.StatusInternalServerError)
							return
						}
					}
				}

				w.WriteHeader(http.StatusOK)
				return
			}

			log.Println("[DEBUG] skipping state handler for request", r.RequestURI)

			// Pass through to application
			next.ServeHTTP(w, r)
		})
	}
}
// stateHandlerMiddleware responds to the various states that are
// given during provider verification
//
// statehandler accepts a state object from the verifier and executes
// any state handlers associated with the provider.
// It will not execute further middleware if it is the designted "state" request