````md magic-move {lines: true}
```go {all|2|2,6-9}
-func forwardContentToTargets(targets ...io.Writer, source io.Reader) error {
+func forwardContentToTargets(source io.Reader, targets ...io.Writer) error {
bytes, err := io.ReadAll(source) // read the source
if err != nil {
return err
@@ -149,7 +120,7 @@ func forwardContentToTargets(targets ...io.Writer, source io.Reader) error {
```
```go {3,5|all}
-func forwardContentToTargets(targets ...io.Writer, source io.Reader) error {
+func forwardContentToTargets(source io.Reader, targets ...io.Writer) error {
// create a writer that includes all targets
dsts := io.MultiWriter(targets)
// read the source and transfer it
@@ -167,9 +138,9 @@ transition: fade-out
layout: lblue-fact
---
-Gem #1: use io.Copy when transferring data
+Gem #1: delegate the complexity of the code to the standard library
-use io.Read* when using that data
+use io.Copy when transferring data
---
@@ -178,9 +149,7 @@ transition: fade-out
# Example #2
-Error creation
-
-Let's see how errors can be created in Go code
+Creating new errors
````md magic-move {lines: true}
@@ -210,28 +179,7 @@ err := fmt.Errorf("an error occurred: %s", oErr.Error())
----
-transition: fade-out
-layout: lblue-fact
----
-
-A human cares about the error message
-
-
-*a program cares more about what kind of error it is
-
-
----
-transition: fade-out
----
-
-# Example #2
-
-Error wrapping
-
-To our help, error wrapping was released with Go [v1.13](https://tip.golang.org/doc/go1.13#error_wrapping) (Sep 2019)
-
-And more recently, multi-error wrapping with Go [v1.20](https://tip.golang.org/doc/go1.20#errors) (Feb 2023)
+To our help, error wrapping was released with Go [v1.13](https://tip.golang.org/doc/go1.13#error_wrapping) (Sep 2019) and multi-error wrapping with Go [v1.20](https://tip.golang.org/doc/go1.20#errors) (Feb 2023)
````md magic-move {lines: true}
@@ -258,25 +206,15 @@ err := errors.Join(oErr1, oErr2, oErr3)
````
-
-
-By __wrapping__ an error you are creating a new error telling which kind it is
-
-By using __errors.As__ and __errors.Is__ you can test an error for what it may be instead of what kind of message it contains
-
-
---
transition: fade-out
layout: lblue-fact
---
-Gem #2: wrap errors with %w or errors.Join
+Gem #2: A human cares about the error message
-*changing from %[s|q|v] to %w is transparent
-
-
-most of the times
+a program cares more about what kind of error it is
@@ -288,12 +226,10 @@ transition: fade-out
# Example #3
-Slices and maps packages
+Slices and maps packages (manipulating an http.Header)
-As a _proxy server_, I want to manipulate an input header from an HTTP request by adding some custom headers and removing others
-
````md magic-move {lines: true}
```go
// http.Header is an alias for map[string][]string
@@ -322,23 +258,17 @@ func update(h http.Header, toAdd http.Header, toDelete []string) {
```
````
-Generics were released with Go [v1.21](https://tip.golang.org/doc/go1.21#library) (Aug 2023)
-
-In the same release, __maps__ and __slices__ packages were introduced to simplify operations made on them
+__Maps__ and __slices__ packages were released with Go [v1.21](https://tip.golang.org/doc/go1.21#library) (Aug 2023) together with generics and use them to simplify maps and slices operations
-
-
---
transition: fade-out
layout: lblue-fact
---
-Gem #3: use maps and slices packages
+Gem #3: check new Go features as they released
-and reduce the complexity of the code dealing with them
+and see how they can be used to simplify your code
---