-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.slide
119 lines (58 loc) · 1.88 KB
/
api.slide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
API Abfrage mit GO
Mar 2018
Tags: go golang
Holger Wetzel
on a learning go journey
@howetze_
https://howetze.github.io/
* Definition Type
- schon ziemlich lange Linux Anfänger
- Go Anfänger
- Frühchenverein Tübingen
.link http://www.lichtblick-tuebingen.de
- LT28 Sven Hedin
- Maas Neotek Biochips Division
* Gopher
.image https://golang.org/doc/gopher/frontpage.png
.caption _Gopher_ by [[http://reneefrench.blogspot.com/][Renée French]]
* API to access
.image https://luftdaten.info/wp-content/uploads/2017/03/feinstaub-sensor.jpg _ 600
.link http://luftdaten.info/
* access to API
Request:
.link http://api.luftdaten.info/v1/sensor/6940/
Response:
.iframe http://api.luftdaten.info/v1/sensor/6940/ 80 950
* generate Struct
.link https://mholt.github.io/json-to-go/
.iframe https://mholt.github.io/json-to-go/ 600 1050
* define Struct
File: temperature/dht/struct.go
.code api/dht/struct.go
* Import Folder with Struct
.code api/apitest.go /start outScope/,/end outScope/
Package names
When a package is imported, the package name becomes an accessor for the contents. After
import "bytes"
the importing package can talk about bytes.Buffer.
.link https://golang.org/doc/effective_go.html#package-names
* Get response
.code api/apitest.go /start outScope/,/end outScope/
* Fill struct
func main {
.code api/apitest.go /start tmp OMIT/,/end tmp OMIT
}
* Print Temperature
.code api/apitest.go /start print OMIT/,/end print OMIT
// r[0] - vorheriger Wert
// r[1] - aktueller Wert
// Sensordatavalues[0] - Temperatur
// Sensordatavalues[1] - Humidity
* Example Go code
.play -edit api/apitest.go /start inScope/,/end inScope/
* JSON and GO
More info about Marshal
.link https://blog.golang.org/json-and-go
Very good resource: Todd Mc Leod on youtube "Golang JSON Marshal"
.link https://www.youtube.com/watch?v=2BmMZNAha38