mirror of https://github.com/dapr/quickstarts.git
go: update code to more modern version
Signed-off-by: Victor Login <batazor@evrone.com>
This commit is contained in:
parent
dfde545821
commit
82fe7b111a
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue