Skip to content

Commit f96d518

Browse files
setup docker and parse json
0 parents  commit f96d518

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

app/Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM golang:1.10.3-alpine
2+
3+
RUN mkdir /app
4+
ADD . /app/
5+
WORKDIR /app
6+
RUN go build -o main .
7+
EXPOSE 8080
8+
CMD ["/app/main"]

app/app.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
"net/http"
8+
"os"
9+
)
10+
11+
type Recipe struct {
12+
Id string
13+
Name string
14+
Headline string
15+
Description string
16+
Difficulty int
17+
PrepTime string
18+
ImageLink string
19+
Ingredients []struct {
20+
Name string
21+
ImageLink string
22+
}
23+
}
24+
25+
func main() {
26+
resp, err := http.Get("https://s3-eu-west-1.amazonaws.com/test-golang-recipes/1")
27+
check(err)
28+
body, err := ioutil.ReadAll(resp.Body)
29+
check(err)
30+
var recipe Recipe
31+
err = json.Unmarshal(body, &recipe)
32+
check(err)
33+
fmt.Println(recipe)
34+
}
35+
36+
func check(err error) {
37+
if err != nil {
38+
fmt.Println(err)
39+
os.Exit(1)
40+
}
41+
}

docker-compose.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: '2'
2+
services:
3+
app:
4+
build: ./app
5+
ports:
6+
- "8080:8080"

0 commit comments

Comments
 (0)