Skip to content

Commit 720dba8

Browse files
committed
multi query ordering, legend param skeleton
1 parent eabf689 commit 720dba8

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

pkg/hander.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sort"
1212
"strconv"
1313
"strings"
14+
"text/template"
1415
"time"
1516

1617
"github.com/go-graphite/carbonapi/date"
@@ -60,7 +61,9 @@ func formatLegend(nameMap map[string]string) string {
6061

6162
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
6263
type G struct {
63-
Expr string
64+
Expr string
65+
Legend string
66+
Template *template.Template
6467
}
6568
params := struct {
6669
G map[int]*G `form:"-"`
@@ -99,6 +102,18 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
99102
return
100103
}
101104

105+
for index, gr := range params.G {
106+
gr.Legend = r.URL.Query().Get(fmt.Sprintf("g%d.legend", index))
107+
if gr.Legend != "" {
108+
t, err := template.New("legend").Parse(gr.Legend)
109+
if err != nil {
110+
http.Error(w, err.Error(), http.StatusBadRequest)
111+
return
112+
}
113+
gr.Template = t
114+
}
115+
}
116+
102117
draftPictureParams := png.GetPictureParams(r, nil)
103118

104119
ctx, cancel := context.WithTimeout(r.Context(), params.Timeout)
@@ -121,7 +136,14 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
121136
}
122137
u.Path = h.queryRangePath
123138

124-
for _, graphData := range params.G {
139+
indexes := make([]int, 0, len(params.G))
140+
for index, _ := range params.G {
141+
indexes = append(indexes, index)
142+
}
143+
sort.Ints(indexes)
144+
145+
for _, index := range indexes {
146+
graphData := params.G[index]
125147
q := u.Query()
126148
q.Set("query", graphData.Expr)
127149
q.Set("start", strconv.Itoa(int(from32)))

0 commit comments

Comments
 (0)