prow/pluginhelp/externalplugins/externalplugins.go
func ServeExternalPluginHelp(mux *http.ServeMux, log *logrus.Entry, provider ExternalPluginHelpProvider) {
	mux.HandleFunc(
		"/help",
		func(w http.ResponseWriter, r *http.Request) {
			w.Header().Set("Cache-Control", "no-cache")

			serverError := func(action string, err error) {
				log.WithError(err).Errorf("Error %s.", action)
				msg := fmt.Sprintf("500 Internal server error %s: %v", action, err)
				http.Error(w, msg, http.StatusInternalServerError)
			}

			if r.Method != http.MethodPost {
				log.Errorf("Invalid request method: %v.", r.Method)
				http.Error(w, "405 Method not allowed", http.StatusMethodNotAllowed)
				return
			}
			b, err := ioutil.ReadAll(r.Body)
			if err != nil {
				serverError("reading request body", err)
				return
			}
			var enabledRepos []string
			if err := json.Unmarshal(b, &enabledRepos); err != nil {
				serverError("unmarshaling request body", err)
				return
			}
			if provider == nil {
				serverError("generating plugin help", errors.New("help provider is nil"))
				return
			}
			help, err := provider(enabledRepos)
			if err != nil {
				serverError("generating plugin help", err)
				return
			}
			b, err = json.Marshal(help)
			if err != nil {
				serverError("marshaling plugin help", err)
				return
			}

			fmt.Fprint(w, string(b))
		},
	)
}
func ServeExternalPluginHelp(mux *http.ServeMux, log *logrus.Entry, provider ExternalPluginHelpProvider) {
	mux.HandleFunc(
		"/help",
		func(w http.ResponseWriter, r *http.Request) {
			w.Header().Set("Cache-Control", "no-cache")

			serverError := func(action string, err error) {
				log.WithError(err).Errorf("Error %s.", action)
				msg := fmt.Sprintf("500 Internal server error %s: %v", action, err)
				http.Error(w, msg, http.StatusInternalServerError)
			}

			if r.Method != http.MethodPost {
				log.Errorf("Invalid request method: %v.", r.Method)
				http.Error(w, "405 Method not allowed", http.StatusMethodNotAllowed)
				return
			}
			b, err := ioutil.ReadAll(r.Body)
			if err != nil {
				serverError("reading request body", err)
				return
			}
			var enabledRepos []string
			if err := json.Unmarshal(b, &enabledRepos); err != nil {
				serverError("unmarshaling request body", err)
				return
			}
			if provider == nil {
				serverError("generating plugin help", errors.New("help provider is nil"))
				return
			}
			help, err := provider(enabledRepos)
			if err != nil {
				serverError("generating plugin help", err)
				return
			}
			b, err = json.Marshal(help)
			if err != nil {
				serverError("marshaling plugin help", err)
				return
			}

			fmt.Fprint(w, string(b))
		},
	)
}
func ServeExternalPluginHelp ( mux * http . ServeMux , log * logrus . Entry , provider ExternalPluginHelpProvider ) { mux . HandleFunc ( " " , func ( w http . ResponseWriter , r * http . Request ) { w . Header ( ) . Set ( " " , " " ) serverError := func ( action string , err error ) { log . WithError ( err ) . Errorf ( " " , action ) msg := fmt . Sprintf ( " " , action , err ) http . Error ( w , msg , http . StatusInternalServerError ) } if r . Method != http . MethodPost { log . Errorf ( " " , r . Method ) http . Error ( w , " " , http . StatusMethodNotAllowed ) return } b , err := ioutil . ReadAll ( r . Body ) if err != nil { serverError ( " " , err ) return } var enabledRepos [ ] string if err := json . Unmarshal ( b , & enabledRepos ) ; err != nil { serverError ( " " , err ) return } if provider == nil { serverError ( " " , errors . New ( " " ) ) return } help , err := provider ( enabledRepos ) if err != nil { serverError ( " " , err ) return } b , err = json . Marshal ( help ) if err != nil { serverError ( " " , err ) return } fmt . Fprint ( w , string ( b ) ) } , ) }
// ServeExternalPluginHelp returns a HandlerFunc that serves plugin help information that is
// provided by the specified ExternalPluginHelpProvider.
ServeExternalPluginHelp returns a HandlerFunc that serves plugin help information that is provided by the specified ExternalPluginHelpProvider .