github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/server/export.go (about)

     1  package server
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"net/http"
     7  
     8  	"github.com/pyroscope-io/pyroscope/pkg/server/httputils"
     9  )
    10  
    11  type Payload struct {
    12  	Name    string
    13  	Profile string
    14  	Type    string
    15  }
    16  
    17  func (ctrl *Controller) exportHandler() http.HandlerFunc {
    18  	return NewExportHandler(ctrl.httpUtils)
    19  }
    20  
    21  func NewExportHandler(httpUtils httputils.Utils) http.HandlerFunc {
    22  	return func(w http.ResponseWriter, r *http.Request) {
    23  		resp, err := http.Post("https://flamegraph.com/api/upload/v1", "application/json", r.Body)
    24  		if err != nil {
    25  			httpUtils.WriteError(r, w, 500, err, fmt.Sprintf("could not upload profile: %v", err))
    26  			return
    27  		}
    28  		defer resp.Body.Close()
    29  		w.Header().Set("Content-Type", "application/json")
    30  		w.WriteHeader(resp.StatusCode)
    31  		io.Copy(w, resp.Body)
    32  	}
    33  }