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

chore: remove pkg/errors dependency + lint fixes #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 11 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"fmt"
"io"
"net/http"
"unicode"

"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -71,7 +70,7 @@ post:
resp,
)
if err != nil {
return nil, nil, errors.Wrap(err, "could not unmarshal app store response")
return nil, nil, fmt.Errorf("could not unmarshal app store response: %w", err)
}

if c.autofixEnvironment {
Expand Down Expand Up @@ -114,14 +113,14 @@ func (c *client) post(ctx context.Context, receiptRequest *ReceiptRequest) ([]by

reqJSON, err := json.Marshal(receiptRequest)
if err != nil {
return nil, errors.Wrap(err, "could not marshal receipt request")
return nil, fmt.Errorf("could not marshal receipt request: %w", err)
}

// Dial the App Store server:

buf := bytes.NewReader(reqJSON)

req, err := http.NewRequest("POST", c.verificationURL, buf)
req, err := http.NewRequest(http.MethodPost, c.verificationURL, buf)
if err != nil {
return nil, err
}
Expand All @@ -131,17 +130,19 @@ func (c *client) post(ctx context.Context, receiptRequest *ReceiptRequest) ([]by
if err != nil {
// TODO: Handle this error (and probably retry at least once):
// Post https://sandbox.itunes.apple.com/verifyReceipt: read tcp 10.1.11.101:36372->17.154.66.159:443: read: connection reset by peer
return nil, errors.Wrap(err, "could not connect to app store server")
return nil, fmt.Errorf("could not connect to app store server: %w", err)
}
defer r.Body.Close()

if r.StatusCode != http.StatusOK {
return nil, errors.New("app store http error (" + r.Status + ")")
return nil, fmt.Errorf("app store http error (%s)", r.Status)
}

// Parse response:

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return nil, errors.Wrap(err, "could not read app store response")
return nil, fmt.Errorf("could not read app store response: %w", err)
}

return body, nil
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/Gurpartap/storekit-go

go 1.14

require github.com/pkg/errors v0.9.1
go 1.16
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2 changes: 1 addition & 1 deletion receipt_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package storekit
type ReceiptResponseStatus int

const (
// Undocumented but occurs
// Undocumented but occurs.
ReceiptResponseStatusUnknown ReceiptResponseStatus = -1

// Receipt is valid.
Expand Down