From f3f5d06bcf4b6b9f8e187c2b3f1c9c3ffe7e936a Mon Sep 17 00:00:00 2001 From: teivah Date: Fri, 4 Feb 2022 21:54:30 +0100 Subject: [PATCH] Reviews --- .../6-interface-producer/store/store.go | 2 +- 03-data-types/19-floating-points/main.go | 6 ++++++ 03-data-types/20-slice-length-cap/main.go | 4 +--- 05-strings/37-string-iteration/main.go | 3 +++ .../43-named-result-parameters/main.go | 10 +++------- 07-error-management/50-compare-error-type/main.go | 7 +++---- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/02-code-project-organization/6-interface-producer/store/store.go b/02-code-project-organization/6-interface-producer/store/store.go index 75d7a2f..bad6042 100644 --- a/02-code-project-organization/6-interface-producer/store/store.go +++ b/02-code-project-organization/6-interface-producer/store/store.go @@ -1,6 +1,6 @@ package store -type Storer interface { +type CustomerStorage interface { StoreCustomer(customer Customer) error GetCustomer(id string) (Customer, error) UpdateCustomer(customer Customer) error diff --git a/03-data-types/19-floating-points/main.go b/03-data-types/19-floating-points/main.go index 03d968b..c82d57a 100644 --- a/03-data-types/19-floating-points/main.go +++ b/03-data-types/19-floating-points/main.go @@ -5,6 +5,12 @@ import "fmt" func main() { var n float32 = 1.0001 fmt.Println(n * n) + + var a float64 + positiveInf := 1 / a + negativeInf := -1 / a + nan := a / a + fmt.Println(positiveInf, negativeInf, nan) } func f1(n int) float64 { diff --git a/03-data-types/20-slice-length-cap/main.go b/03-data-types/20-slice-length-cap/main.go index b54130f..3d4d260 100644 --- a/03-data-types/20-slice-length-cap/main.go +++ b/03-data-types/20-slice-length-cap/main.go @@ -12,9 +12,7 @@ func main() { s = append(s, 2) print(s) - s = append(s, 3) - s = append(s, 4) - s = append(s, 5) + s = append(s, 3, 4, 5) print(s) s1 := make([]int, 3, 6) diff --git a/05-strings/37-string-iteration/main.go b/05-strings/37-string-iteration/main.go index f3e9fc0..1a5c096 100644 --- a/05-strings/37-string-iteration/main.go +++ b/05-strings/37-string-iteration/main.go @@ -17,6 +17,9 @@ func main() { for i, r := range runes { fmt.Printf("position %d: %c\n", i, r) } + + s2 := "hello" + fmt.Printf("%c\n", rune(s2[4])) } func getIthRune(largeString string, i int) rune { diff --git a/06-functions-methods/43-named-result-parameters/main.go b/06-functions-methods/43-named-result-parameters/main.go index 24e954a..16ecba0 100644 --- a/06-functions-methods/43-named-result-parameters/main.go +++ b/06-functions-methods/43-named-result-parameters/main.go @@ -1,5 +1,7 @@ package main +import "io" + func f(a int) (b int) { b = a return @@ -16,7 +18,7 @@ func (l loc) getCoordinates(address string) (lat, lng float32, err error) { return 0, 0, nil } -func ReadFull(r Reader, buf []byte) (n int, err error) { +func ReadFull(r io.Reader, buf []byte) (n int, err error) { for len(buf) > 0 && err == nil { var nr int nr, err = r.Read(buf) @@ -25,9 +27,3 @@ func ReadFull(r Reader, buf []byte) (n int, err error) { } return } - -type Reader struct{} - -func (Reader) Read([]byte) (int, error) { - return 0, nil -} diff --git a/07-error-management/50-compare-error-type/main.go b/07-error-management/50-compare-error-type/main.go index e21f427..828bfef 100644 --- a/07-error-management/50-compare-error-type/main.go +++ b/07-error-management/50-compare-error-type/main.go @@ -14,7 +14,7 @@ func (t transientError) Error() string { return fmt.Sprintf("transient error: %v", t.err) } -func GetTransactionAmountHandler(w http.ResponseWriter, r *http.Request) { +func handler(w http.ResponseWriter, r *http.Request) { transactionID := r.URL.Query().Get("transaction") amount, err := getTransactionAmount1(transactionID) @@ -48,13 +48,12 @@ func getTransactionAmountFromDB1(id string) (float32, error) { return 0, nil } -func GetTransactionAmount2(w http.ResponseWriter, r *http.Request) { +func handler2(w http.ResponseWriter, r *http.Request) { transactionID := r.URL.Query().Get("transaction") amount, err := getTransactionAmount2(transactionID) if err != nil { - terr := transientError{} - if errors.As(err, &terr) { + if errors.As(err, &transientError{}) { http.Error(w, err.Error(), http.StatusServiceUnavailable) } else { http.Error(w, err.Error(), http.StatusBadRequest)