Skip to content

Commit

Permalink
api: Add meta report type
Browse files Browse the repository at this point in the history
  • Loading branch information
brancz committed Oct 15, 2020
1 parent 233fe75 commit 9095c5a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions api/api.go
Expand Up @@ -332,6 +332,12 @@ func (a *API) Query(r *http.Request) (interface{}, []error, *ApiError) {
}

switch r.URL.Query().Get("report") {
case "meta":
meta, err := generateMetaReport(profile)
if err != nil {
return nil, nil, &ApiError{Typ: ErrorExec, Err: err}
}
return meta, nil, nil
case "top":
top, err := generateTopReport(profile)
if err != nil {
Expand All @@ -353,6 +359,32 @@ func (a *API) Query(r *http.Request) (interface{}, []error, *ApiError) {
}
}

type valueType struct {
Type string `json:"type,omitempty"`
}

type metaReport struct {
SampleTypes []valueType `json:"sampleTypes"`
DefaultSampleType string `json:"defaultSampleType"`
}

func generateMetaReport(profile *profile.Profile) (*metaReport, error) {
index, err := profile.SampleIndexByName("")
if err != nil {
return nil, err
}

res := &metaReport{
SampleTypes: []valueType{},
DefaultSampleType: profile.SampleType[index].Type,
}
for _, t := range profile.SampleType {
res.SampleTypes = append(res.SampleTypes, valueType{t.Type})
}

return res, nil
}

type protoRenderer struct {
profile *profile.Profile
}
Expand Down

0 comments on commit 9095c5a

Please sign in to comment.