From 82fe7b111a72deb0b2eaca790790fd898d81ed93 Mon Sep 17 00:00:00 2001 From: Victor Login Date: Mon, 3 Jul 2023 20:08:07 +0200 Subject: [PATCH] go: update code to more modern version Signed-off-by: Victor Login --- bindings/go/http/batch/app.go | 4 ++-- bindings/go/sdk/batch/app.go | 4 ++-- configuration/go/http/order-processor/app.go | 10 +++++----- pub_sub/go/http/order-processor/app.go | 7 ++++--- secrets_management/go/http/order-processor/app.go | 4 ++-- service_invocation/go/http/checkout/app.go | 4 ++-- service_invocation/go/http/order-processor/app.go | 7 ++++--- state_management/go/http/order-processor/app.go | 4 ++-- 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/bindings/go/http/batch/app.go b/bindings/go/http/batch/app.go index edf62a82d..54a6f697f 100644 --- a/bindings/go/http/batch/app.go +++ b/bindings/go/http/batch/app.go @@ -20,7 +20,7 @@ dapr run --app-id batch-http --app-port 6003 --dapr-http-port 3503 --dapr-grpc-p import ( "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -56,7 +56,7 @@ func processBatch(w http.ResponseWriter, r *http.Request) { defer fileContent.Close() - byteResult, _ := ioutil.ReadAll(fileContent) + byteResult, _ := io.ReadAll(fileContent) var orders Orders diff --git a/bindings/go/sdk/batch/app.go b/bindings/go/sdk/batch/app.go index cd7ce9273..11a12477b 100644 --- a/bindings/go/sdk/batch/app.go +++ b/bindings/go/sdk/batch/app.go @@ -21,7 +21,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -57,7 +57,7 @@ func processBatch(w http.ResponseWriter, r *http.Request) { defer fileContent.Close() - byteResult, _ := ioutil.ReadAll(fileContent) + byteResult, _ := io.ReadAll(fileContent) var orders Orders diff --git a/configuration/go/http/order-processor/app.go b/configuration/go/http/order-processor/app.go index b61c92908..66ba60177 100644 --- a/configuration/go/http/order-processor/app.go +++ b/configuration/go/http/order-processor/app.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -39,7 +39,7 @@ func main() { fmt.Print("Could not get config item, err:" + err.Error()) os.Exit(1) } - result, _ := ioutil.ReadAll(getResponse.Body) + result, _ := io.ReadAll(getResponse.Body) fmt.Println("Configuration for "+item+":", string(result)) } @@ -69,7 +69,7 @@ func subscribeToConfigUpdates(subscriptionId *string) { fmt.Println("Error subscribing to config updates, err:" + err.Error()) os.Exit(1) } - sub, err := ioutil.ReadAll(subscription.Body) + sub, err := io.ReadAll(subscription.Body) if err != nil { fmt.Print("Unable to read subscription id, err: " + err.Error()) os.Exit(1) @@ -115,7 +115,7 @@ func unsubscribeFromConfigUpdates(subscriptionId string) { if err != nil { fmt.Println("Error unsubscribing from config updates, err:" + err.Error()) } - unsub, err := ioutil.ReadAll(unsubscribe.Body) + unsub, err := io.ReadAll(unsubscribe.Body) if err != nil { fmt.Print("Unable to read unsubscribe response, err: " + err.Error()) } @@ -128,7 +128,7 @@ func unsubscribeFromConfigUpdates(subscriptionId string) { } func configUpdateHandler(w http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { log.Panic(err) } diff --git a/pub_sub/go/http/order-processor/app.go b/pub_sub/go/http/order-processor/app.go index 3ee9344eb..1438f1064 100644 --- a/pub_sub/go/http/order-processor/app.go +++ b/pub_sub/go/http/order-processor/app.go @@ -2,8 +2,9 @@ package main import ( "encoding/json" + "errors" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -40,7 +41,7 @@ func getOrder(w http.ResponseWriter, r *http.Request) { } func postOrder(w http.ResponseWriter, r *http.Request) { - data, err := ioutil.ReadAll(r.Body) + data, err := io.ReadAll(r.Body) if err != nil { log.Fatal(err) } @@ -79,7 +80,7 @@ func main() { // Start the server; this is a blocking call err := http.ListenAndServe(":"+appPort, r) - if err != http.ErrServerClosed { + if !errors.Is(err, http.ErrServerClosed) { log.Panic(err) } } diff --git a/secrets_management/go/http/order-processor/app.go b/secrets_management/go/http/order-processor/app.go index 07da0e56c..4e9b663a9 100644 --- a/secrets_management/go/http/order-processor/app.go +++ b/secrets_management/go/http/order-processor/app.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "net/http" "os" ) @@ -25,6 +25,6 @@ func main() { fmt.Print(err.Error()) os.Exit(1) } - result, _ := ioutil.ReadAll(getResponse.Body) + result, _ := io.ReadAll(getResponse.Body) fmt.Println("Fetched Secret: ", string(result)) } diff --git a/service_invocation/go/http/checkout/app.go b/service_invocation/go/http/checkout/app.go index 4c7866b46..34bbf77f2 100644 --- a/service_invocation/go/http/checkout/app.go +++ b/service_invocation/go/http/checkout/app.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -40,7 +40,7 @@ func main() { } // Read the response - result, err := ioutil.ReadAll(response.Body) + result, err := io.ReadAll(response.Body) if err != nil { log.Fatal(err) } diff --git a/service_invocation/go/http/order-processor/app.go b/service_invocation/go/http/order-processor/app.go index 2da385e8d..4c3089dcd 100644 --- a/service_invocation/go/http/order-processor/app.go +++ b/service_invocation/go/http/order-processor/app.go @@ -1,8 +1,9 @@ package main import ( + "errors" "fmt" - "io/ioutil" + "io" "log" "net/http" @@ -10,7 +11,7 @@ import ( ) func getOrder(w http.ResponseWriter, r *http.Request) { - data, err := ioutil.ReadAll(r.Body) + data, err := io.ReadAll(r.Body) if err != nil { log.Println("Error reading body:", err.Error()) } @@ -29,7 +30,7 @@ func main() { // Start the server listening on port 6001 // This is a blocking call err := http.ListenAndServe(":6006", r) - if err != http.ErrServerClosed { + if !errors.Is(err, http.ErrServerClosed) { log.Println("Error starting HTTP server") } } diff --git a/state_management/go/http/order-processor/app.go b/state_management/go/http/order-processor/app.go index 6d5d11a3a..863c0ff19 100644 --- a/state_management/go/http/order-processor/app.go +++ b/state_management/go/http/order-processor/app.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -51,7 +51,7 @@ func main() { if err != nil { panic(err) } - result, err := ioutil.ReadAll(getResponse.Body) + result, err := io.ReadAll(getResponse.Body) if err != nil { panic(err) }