From 8c43b971793ecc8d653949953b856faf7d944f2b Mon Sep 17 00:00:00 2001 From: Fatih Sarhan Date: Sun, 24 Mar 2019 22:06:38 +0300 Subject: [PATCH] Use the pure function instead of the separated util package --- models/date.go | 9 ++++----- routers/routers.go | 14 +++++++------- util/util.go | 10 ---------- 3 files changed, 11 insertions(+), 22 deletions(-) delete mode 100644 util/util.go diff --git a/models/date.go b/models/date.go index bcf001e..e86cd29 100644 --- a/models/date.go +++ b/models/date.go @@ -2,9 +2,8 @@ package models import ( "fmt" + "strconv" "strings" - - "github.com/GnuYtuce/ytuyemekhane-api/util" ) type Date struct { @@ -25,9 +24,9 @@ const ( func NewDate(dateStr string) *Date { var d Date temp := strings.Split(dateStr, ".") - d.Day, _ = util.StringToInt(temp[0]) - d.Month, _ = util.StringToInt(strings.TrimLeft(temp[1], "0")) - d.Year, _ = util.StringToInt(temp[2]) + d.Day, _ = strconv.Atoi(temp[0]) + d.Month, _ = strconv.Atoi(strings.TrimLeft(temp[1], "0")) + d.Year, _ = strconv.Atoi(temp[2]) return &d } diff --git a/routers/routers.go b/routers/routers.go index 860b817..4eb8d6a 100644 --- a/routers/routers.go +++ b/routers/routers.go @@ -3,13 +3,13 @@ package routers import ( "errors" "net/http" + "strconv" "sync" "time" "github.com/GnuYtuce/ytuyemekhane-api/crawler" "github.com/GnuYtuce/ytuyemekhane-api/models" "github.com/GnuYtuce/ytuyemekhane-api/sender" - "github.com/GnuYtuce/ytuyemekhane-api/util" "github.com/julienschmidt/httprouter" ) @@ -37,7 +37,7 @@ func FoodListByCurrentTime(w http.ResponseWriter, r *http.Request, p httprouter. // FoodListByCertainYear : belli bir yila gore yemek listesi donulecek. func FoodListByCertainYear(w http.ResponseWriter, r *http.Request, p httprouter.Params) { - year, _ := util.StringToInt(p.ByName("year")) + year, _ := strconv.Atoi(p.ByName("year")) date := models.Date{ Day: 0, Month: 0, @@ -75,8 +75,8 @@ func FoodListByCertainYear(w http.ResponseWriter, r *http.Request, p httprouter. // FoodListByCertainYearAndMonth : belli bir yil ve aya gore yemek listesi donulecek. func FoodListByCertainYearAndMonth(w http.ResponseWriter, r *http.Request, p httprouter.Params) { - month, _ := util.StringToInt(p.ByName("month")) - year, _ := util.StringToInt(p.ByName("year")) + month, _ := strconv.Atoi(p.ByName("month")) + year, _ := strconv.Atoi(p.ByName("year")) date := models.Date{ Day: 0, Month: month, @@ -93,9 +93,9 @@ func FoodListByCertainYearAndMonth(w http.ResponseWriter, r *http.Request, p htt // FoodListByCertainTime : belli bir zamana gore yemek listesi donulecek. func FoodListByCertainTime(w http.ResponseWriter, r *http.Request, p httprouter.Params) { - day, _ := util.StringToInt(p.ByName("day")) - month, _ := util.StringToInt(p.ByName("month")) - year, _ := util.StringToInt(p.ByName("year")) + day, _ := strconv.Atoi(p.ByName("day")) + month, _ := strconv.Atoi(p.ByName("month")) + year, _ := strconv.Atoi(p.ByName("year")) date := models.Date{ Day: day, Month: month, diff --git a/util/util.go b/util/util.go deleted file mode 100644 index f5ff01b..0000000 --- a/util/util.go +++ /dev/null @@ -1,10 +0,0 @@ -package util - -import ( - "strconv" -) - -// StringToInt : "string" turundeki degiskeni "int" turune cevirir. -func StringToInt(value string) (int, error) { - return strconv.Atoi(value) -}