Skip to content

Commit 807acf9

Browse files
authored
implement deep copy (#916)
1 parent e78cfd5 commit 807acf9

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

backend/data.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type DataQuery struct {
111111
// It is the return type of a QueryData call.
112112
type QueryDataResponse struct {
113113
// Responses is a map of RefIDs (Unique Query ID) to *DataResponse.
114-
Responses Responses
114+
Responses Responses `json:"results"`
115115
}
116116

117117
// MarshalJSON writes the results as json
@@ -131,6 +131,30 @@ func (r *QueryDataResponse) UnmarshalJSON(b []byte) error {
131131
return iter.Error
132132
}
133133

134+
func (r *QueryDataResponse) DeepCopy() *QueryDataResponse {
135+
if r == nil {
136+
return nil
137+
}
138+
out := new(QueryDataResponse)
139+
r.DeepCopyInto(out)
140+
return out
141+
}
142+
143+
func (r *QueryDataResponse) DeepCopyInto(out *QueryDataResponse) {
144+
if r.Responses == nil {
145+
out.Responses = nil
146+
return
147+
}
148+
if out.Responses == nil {
149+
out.Responses = make(Responses, len(r.Responses))
150+
} else {
151+
clear(out.Responses)
152+
}
153+
for k, v := range r.Responses {
154+
out.Responses[k] = *v.DeepCopy()
155+
}
156+
}
157+
134158
// NewQueryDataResponse returns a QueryDataResponse with the Responses property initialized.
135159
func NewQueryDataResponse() *QueryDataResponse {
136160
return &QueryDataResponse{
@@ -191,6 +215,19 @@ func (r DataResponse) MarshalJSON() ([]byte, error) {
191215
return append([]byte(nil), stream.Buffer()...), stream.Error
192216
}
193217

218+
func (r *DataResponse) DeepCopy() *DataResponse {
219+
if r == nil {
220+
return nil
221+
}
222+
out := &DataResponse{}
223+
body, err := r.MarshalJSON()
224+
if err == nil {
225+
iter := jsoniter.ParseBytes(jsoniter.ConfigDefault, body)
226+
readDataResponseJSON(out, iter)
227+
}
228+
return out
229+
}
230+
194231
// TimeRange represents a time range for a query and is a property of DataQuery.
195232
type TimeRange struct {
196233
// From is the start time of the query.

data/frame_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
// frame's structure conforms to the FrameType's specification.
1111
// This property is currently optional, so FrameType may be FrameTypeUnknown even if the properties of
1212
// the Frame correspond to a defined FrameType.
13+
// +enum
1314
type FrameType string
1415

1516
// ---

0 commit comments

Comments
 (0)