Skip to content

Commit

Permalink
Add docs and images limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaraa committed Jan 4, 2024
1 parent 5f07f67 commit 43d6388
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,24 @@ Sample response:

```json
{
"text": "Great ideas often receive violent opposition from mediocre minds.",
"author": "Albert Einstein"
"text": "Great ideas often receive violent opposition from mediocre minds.",
"author": "Albert Einstein"
}
```

**GET https://apis.gdscasu.com/image**

An endpoint that returns quote and who said it, from a pre defined list.

Query parameters:

- `count` (optional): specifies the number of returned images' paths.
- `orientation` (default is landscape): specifies the orientation of the returned image(s).

Sample response:

```json
{
"image": ["/files/images/landscape1.jpg"]
}
```
5 changes: 2 additions & 3 deletions images.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"math"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -54,12 +55,10 @@ func handleGetImage(w http.ResponseWriter, r *http.Request) {
if parsedCount, err := strconv.Atoi(r.URL.Query().Get("count")); err == nil {
count = parsedCount
}

images := []string{getRandomImage(orientation)}
for i := 1; i < count; i++ {
for i := 1; i < int(math.Min(float64(count), float64(len(imagesPaths)))); i++ {
images = append(images, getRandomImage(orientation))
}

_ = json.NewEncoder(w).Encode(map[string]any{
"images": images,
})
Expand Down

0 comments on commit 43d6388

Please sign in to comment.