From d3ebd2a6e53ab601568a82ac40a795b846c1b45c Mon Sep 17 00:00:00 2001 From: Markus Wiegand Date: Sat, 16 May 2020 16:13:43 +0200 Subject: [PATCH] change function parameters --- controller/item.go | 24 ++++++++++++------------ model/model.go | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/controller/item.go b/controller/item.go index a5c0ee6..c6594ab 100644 --- a/controller/item.go +++ b/controller/item.go @@ -163,23 +163,23 @@ Loop: switch kind { case item.KindArmor: - err = filter.AddString(r.URL.Query().Get("type"), "type") - err = filter.AddInt(r.URL.Query().Get("armor.class"), "armor.class") - err = filter.AddString(r.URL.Query().Get("armor.material.name"), "armor.material.name") + err = filter.AddString("type", r.URL.Query().Get("type")) + err = filter.AddInt("armor.class", r.URL.Query().Get("armor.class")) + err = filter.AddString("armor.material.name", r.URL.Query().Get("armor.material.name")) case item.KindFirearm: - err = filter.AddString(r.URL.Query().Get("type"), "type") - err = filter.AddString(r.URL.Query().Get("class"), "class") - err = filter.AddString(r.URL.Query().Get("caliber"), "caliber") + err = filter.AddString("type", r.URL.Query().Get("type")) + err = filter.AddString("class", r.URL.Query().Get("class")) + err = filter.AddString("caliber", r.URL.Query().Get("caliber")) case item.KindTacticalrig: - err = filter.AddInt(r.URL.Query().Get("armor.class"), "armor.class") - err = filter.AddString(r.URL.Query().Get("armor.material.name"), "armor.material.name") + err = filter.AddInt("armor.class", r.URL.Query().Get("armor.class")) + err = filter.AddString("armor.material.name", r.URL.Query().Get("armor.material.name")) case item.KindAmmunition: - err = filter.AddString(r.URL.Query().Get("type"), "type") - err = filter.AddString(r.URL.Query().Get("caliber"), "caliber") + err = filter.AddString("type", r.URL.Query().Get("type")) + err = filter.AddString("caliber", r.URL.Query().Get("caliber")) case item.KindMagazine: - err = filter.AddString(r.URL.Query().Get("caliber"), "caliber") + err = filter.AddString("caliber", r.URL.Query().Get("caliber")) case item.KindMedical, item.KindFood, item.KindGrenade, item.KindClothing, item.KindModificationMuzzle, item.KindModificationDevice, item.KindModificationSight, item.KindModificationSightSpecial, item.KindModificationGoggles: - err = filter.AddString(r.URL.Query().Get("type"), "type") + err = filter.AddString("type", r.URL.Query().Get("type")) } if err != nil { s := &Status{} diff --git a/model/model.go b/model/model.go index 3fe48b2..bbd1b69 100644 --- a/model/model.go +++ b/model/model.go @@ -62,25 +62,25 @@ func NewResponse(msg string, code int) *Response { type Filter map[string]interface{} // AddString adds a string to the given MongoDB field -func (f Filter) AddString(val, path string) error { +func (f Filter) AddString(field, value string) error { var err error - if val != "" { - f[path], err = url.QueryUnescape(val) + if value != "" { + f[field], err = url.QueryUnescape(value) } return err } // AddInt adds an integer to the given MongoDB field -func (f Filter) AddInt(val, path string) error { - if val != "" { +func (f Filter) AddInt(field, value string) error { + if value != "" { var err error - val, err = url.QueryUnescape(val) + value, err = url.QueryUnescape(value) if err != nil { return err } - f[path], err = strconv.ParseInt(val, 10, 64) + f[field], err = strconv.ParseInt(value, 10, 64) if err != nil { return err } @@ -90,15 +90,15 @@ func (f Filter) AddInt(val, path string) error { } // AddFloat adds a float to the given MongoDB field -func (f Filter) AddFloat(val, path string) error { - if val != "" { +func (f Filter) AddFloat(field, value string) error { + if value != "" { var err error - val, err = url.QueryUnescape(val) + value, err = url.QueryUnescape(value) if err != nil { return err } - f[path], err = strconv.ParseFloat(val, 64) + f[field], err = strconv.ParseFloat(value, 64) if err != nil { return err }