Skip to content

Commit 4eb5071

Browse files
run test using docker
1 parent eed3260 commit 4eb5071

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

app/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ RUN mkdir /app
44
ADD . /app/
55
WORKDIR /app
66
RUN go build -o main .
7+
RUN go test -cover
78
EXPOSE 8080
89
CMD ["/app/main"]

app/app.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func AllRecipeHandler(req *http.Request, client *http.Client) []Recipe {
6868
skip := config.DefaultSkip
6969
if len(req.URL.Query()["top"]) > 0 {
7070
top, _ = strconv.Atoi(req.URL.Query()["top"][0])
71+
// Avoid fetching negative ids to reduce traffic
7172
if top < 0 {
7273
top = 0
7374
}
@@ -77,6 +78,7 @@ func AllRecipeHandler(req *http.Request, client *http.Client) []Recipe {
7778
}
7879
if len(req.URL.Query()["skip"]) > 0 {
7980
skip, _ = strconv.Atoi(req.URL.Query()["skip"][0])
81+
// Avoid fetching negative ids to reduce traffic
8082
if skip < 0 {
8183
skip = config.DefaultSkip
8284
}
@@ -91,8 +93,8 @@ func AllRecipeHandler(req *http.Request, client *http.Client) []Recipe {
9193
}
9294

9395
// Fetch recipes with given ids
96+
// To reduce traffic, only those with valid and positive ids are fetched
9497
func AggregatedRecipeHandler(req *http.Request, client *http.Client) []Recipe {
95-
// ids := strings.Split(req.URL.Query()["ids"][0], ",")
9698
ids := Filter(strings.Split(req.URL.Query()["ids"][0], ","), func(s string) bool {
9799
val, _ := strconv.Atoi(s)
98100
return val > 0

0 commit comments

Comments
 (0)