示例#1
0
func handleGetConfig(s api.FluxService) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		inst := getInstanceID(r)
		config, err := s.GetConfig(inst)
		if err != nil {
			w.WriteHeader(http.StatusInternalServerError)
			fmt.Fprintf(w, err.Error())
			return
		}

		configBytes := bytes.Buffer{}
		if err = json.NewEncoder(&configBytes).Encode(config); err != nil {
			w.WriteHeader(http.StatusInternalServerError)
			fmt.Fprintf(w, err.Error())
			return
		}

		w.WriteHeader(http.StatusOK)
		w.Write(configBytes.Bytes())
		return
	})
}