restful apis in go - entwicklertag...small: only 25 keywords break default var interface select case...
TRANSCRIPT
RESTFUL APIS IN GOFrankfurter Entwicklertag 2018
Ralf Wirdemann
Navigate : Space / Arrow Keys | - Menu | - Fullscreen | - Overview | - Blackout | - Speaker | - HelpM F O B S ?
Í
1 / 17
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
2 / 17
GO 101
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
3 / 17
STATICALLY TYPEDvar i int
s := "Hallo" // string
f := 3.142 // float
type struct Product {
Id int
Name string
}
p := Product{1, "Schuhe"}
foo(p)
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
4 / 17
SMALL: ONLY 25 KEYWORDS
break default var interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return func
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
5 / 17
LOOK, I'M FUNCTIONALfunc bar(x int) bool {
return x == 42
}
func foo(f func (x int) bool) bool {
return f(42)
}
func main() {
foo(bar)
}
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
6 / 17
WELL, I'M OO TOOtype Rectangle struct {
size int
border int
}
func (this Rectangle) draw() {
}
r := Rectangle{}
r.draw()
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
7 / 17
CROSS PLATFORM-BINARIES
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
8 / 17
STANDARD LIBRARY
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
9 / 17
NET/HTTPPackage http provides HTTP client and server
implementations.
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
10 / 17
http.Handle("/foo", fooHandler)
func fooHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hey, %q", html.EscapeString(r.URL.Path))
}
log.Fatal(http.ListenAndServe(":8080", nil))
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
11 / 17
ENCODING/JSONPackage json implements encoding and decoding of
JSON as defined in RFC 4627.
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
12 / 17
type Message struct {
Name string
Body string
}
m := Message{"Alice", "Hello"}
b, err := json.Marshal(m)
b == []byte(`{"Name":"Alice","Body":"Hello"}`)
var n Message
err := json.Unmarshal(b, &n)
n == Message{Name: "Alice", Body: "Hello"}
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
13 / 17
REST 101Architecture Style
Resourcen
URIs
HTTP-Verbs
Representations
Hypermedia
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
14 / 17
RESOURCE EXAMPLE
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
15 / 17
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
16 / 17
GO PAIR PROGRAMMING
[ GitPitch @ bitbucket/rwirdemann/rest-apis-go-md/frankfurter-entwicklertag-2018 ]
Í
17 / 17