fix server example

Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
This commit is contained in:
Nicolás Pazos 2023-12-19 12:13:01 -03:00
parent 66f93860ce
commit d61fda90f2

View file

@ -58,7 +58,7 @@ func main() {
}) })
http.HandleFunc("/receiveMinimized", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/receiveMinimized", func(w http.ResponseWriter, r *http.Request) {
req, err := remote.DecodeMinimizedWriteRequest(r.Body) req, err := remote.DecodeMinimizedWriteRequestStr(r.Body)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
return return
@ -70,17 +70,12 @@ func main() {
for labelIdx < len(ts.LabelSymbols) { for labelIdx < len(ts.LabelSymbols) {
// todo, check for overflow? // todo, check for overflow?
offset := ts.LabelSymbols[labelIdx] nameIdx := ts.LabelSymbols[labelIdx]
labelIdx++ labelIdx++
length := ts.LabelSymbols[labelIdx] valueIdx := ts.LabelSymbols[labelIdx]
labelIdx++ labelIdx++
name := req.Symbols[offset : offset+length] name := req.Symbols[nameIdx]
// todo, check for overflow? value := req.Symbols[valueIdx]
offset = ts.LabelSymbols[labelIdx]
labelIdx++
length = ts.LabelSymbols[labelIdx]
labelIdx++
value := req.Symbols[offset : offset+length]
m[model.LabelName(name)] = model.LabelValue(value) m[model.LabelName(name)] = model.LabelValue(value)
} }
fmt.Println(m) fmt.Println(m)