Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to io from ioutil to read body #68

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ package function
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
)
Expand All @@ -225,7 +225,7 @@ func Handle(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()

// read request payload
reqBody, err := ioutil.ReadAll(r.Body)
reqBody, err := io.ReadAll(r.Body)

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -268,7 +268,7 @@ package function
import (
"database/sql"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
_ "github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -298,7 +298,7 @@ func Handle(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()

// read request payload
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -400,14 +400,14 @@ Imagine you have a package which you want to store outside of the `handler.go` f
package handlers

import (
"io/ioutil"
"io"
"net/http"
)

func Echo(w http.ResponseWriter, r *http.Request) {
if r.Body != nil {
defer r.Body.Close()
b, _ := ioutil.ReadAll(r.Body)
b, _ := io.ReadAll(r.Body)
w.Write(b)
}
}
Expand Down
2 changes: 1 addition & 1 deletion template/golang-http/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN mkdir -p /go/src/handler
WORKDIR /go/src/handler
COPY . .

ARG GO111MODULE="off"
ARG GO111MODULE="on"
ARG GOPROXY=""
ARG GOFLAGS=""
ARG DEBUG=0
Expand Down
4 changes: 2 additions & 2 deletions template/golang-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -83,7 +83,7 @@ func makeRequestHandler() func(http.ResponseWriter, *http.Request) {
if r.Body != nil {
defer r.Body.Close()

bodyBytes, bodyErr := ioutil.ReadAll(r.Body)
bodyBytes, bodyErr := io.ReadAll(r.Body)

if bodyErr != nil {
log.Printf("Error reading body from request.")
Expand Down
4 changes: 2 additions & 2 deletions template/golang-middleware/function/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package function

import (
"fmt"
"io/ioutil"
"io"
"net/http"
)

Expand All @@ -12,7 +12,7 @@ func Handle(w http.ResponseWriter, r *http.Request) {
if r.Body != nil {
defer r.Body.Close()

body, _ := ioutil.ReadAll(r.Body)
body, _ := io.ReadAll(r.Body)

input = body
}
Expand Down