diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d764905..0d50075 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: - windows-latest go-version: - 1.x - - 1.13.x + - 1.16.x runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v2 @@ -53,7 +53,12 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: '1.16' + - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@master with: - version: v1.35 + version: v1.37 + skip-go-installation: true diff --git a/.golangci.yml b/.golangci.yml index 5532d29..711bd70 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,14 +7,16 @@ issues: linters: enable-all: true disable: - - lll + - cyclop + - exhaustivestruct + - forbidigo - funlen - - gofumpt - gci + - gofumpt + - ifshort + - lll - nlreturn - - testpackage - - exhaustivestruct - - wrapcheck - paralleltest - - forbidigo + - testpackage - thelper + - wrapcheck diff --git a/README.md b/README.md index a5d8419..4f42159 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ asc-go is a Go client library for accessing Apple's [App Store Connect API](http ## Usage -This project uses Go Modules. +This project uses Go Modules. It requires **Go 1.16 or higher**. ```go import "github.com/cidertool/asc-go/asc" @@ -35,6 +35,7 @@ You may find that the code snippet above will always fail due to a lack of autho ```go import ( + "os" "time" "github.com/cidertool/asc-go/asc" @@ -48,7 +49,7 @@ func main() { // A duration value for the lifetime of a token. App Store Connect does not accept a token with a lifetime of longer than 20 minutes expiryDuration = 20*time.Minute // The bytes of the PKCS#8 private key created on App Store Connect. Keep this key safe as you can only download it once. - privateKey = ioutil.ReadFile("path/to/key") + privateKey = os.ReadFile("path/to/key") auth, err = asc.NewTokenConfig(keyID, issuerID, expiryDuration, privateKey) if err != nil { diff --git a/asc/asc.go b/asc/asc.go index 4644c9c..ce57d52 100644 --- a/asc/asc.go +++ b/asc/asc.go @@ -26,7 +26,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "net/http" "net/http/httputil" @@ -411,7 +410,7 @@ func checkResponse(r *Response) error { return nil } - data, err := ioutil.ReadAll(r.Body) + data, err := io.ReadAll(r.Body) erro := new(ErrorResponse) if err == nil && data != nil { @@ -510,8 +509,7 @@ func (e ErrorResponseError) String(level int) string { // Close closes an open descriptor. func closeDesc(c io.Closer) { - err := c.Close() - if err != nil { + if err := c.Close(); err != nil { log.Fatal(err) } } diff --git a/asc/asc_test.go b/asc/asc_test.go index d928657..5bc05fa 100644 --- a/asc/asc_test.go +++ b/asc/asc_test.go @@ -24,7 +24,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -186,7 +186,7 @@ func TestCheckBadResponse(t *testing.T) { Method: "GET", URL: &url.URL{}, }, - Body: ioutil.NopCloser(strings.NewReader(`{ + Body: io.NopCloser(strings.NewReader(`{ "errors": [ { "code": "", diff --git a/asc/doc.go b/asc/doc.go index f339f5e..f454dae 100644 --- a/asc/doc.go +++ b/asc/doc.go @@ -51,6 +51,7 @@ and rotating JSON Web Tokens automatically. For example, the above snippet could to look a little more like this: import ( + "os" "time" "github.com/cidertool/asc-go/asc" @@ -66,7 +67,7 @@ to look a little more like this: expiryDuration = 20*time.Minute // The bytes of the PKCS#8 private key created on App Store Connect. Keep this key // safe as you can only download it once. - privateKey = ioutil.ReadFile("path/to/key") + privateKey = os.ReadFile("path/to/key") auth, err = asc.NewTokenConfig(keyID, issuerID, expiryDuration, privateKey) if err != nil { diff --git a/asc/provisioning_certificates.go b/asc/provisioning_certificates.go index fc6378c..8787fe0 100644 --- a/asc/provisioning_certificates.go +++ b/asc/provisioning_certificates.go @@ -25,7 +25,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" ) // ErrMissingCSRContent happens when CreateCertificate is provided a nil Reader for processing @@ -144,7 +143,7 @@ func (s *ProvisioningService) CreateCertificate(ctx context.Context, certificate return nil, nil, ErrMissingCSRContent } - csrBytes, err := ioutil.ReadAll(csrContent) + csrBytes, err := io.ReadAll(csrContent) if err != nil { return nil, nil, err } diff --git a/asc/upload_operation_test.go b/asc/upload_operation_test.go index 4ea8935..5c95900 100644 --- a/asc/upload_operation_test.go +++ b/asc/upload_operation_test.go @@ -26,7 +26,6 @@ import ( "crypto/rand" "fmt" "io" - "io/ioutil" "net/http" "os" "testing" @@ -35,7 +34,7 @@ import ( ) func TestMultipartUpload(t *testing.T) { - file, err := ioutil.TempFile("", "big_file") + file, err := os.CreateTemp("", "big_file") if err != nil { assert.FailNow(t, "temp file creation produced an error", err) } @@ -112,7 +111,7 @@ func TestMultipartUpload(t *testing.T) { } func TestUploadOperationChunk(t *testing.T) { - file, err := ioutil.TempFile("", "small_file") + file, err := os.CreateTemp("", "small_file") if err != nil { assert.FailNow(t, "temp file creation produced an error", err) } @@ -153,7 +152,7 @@ func TestUploadOperationChunk(t *testing.T) { } func TestUploadOperationUploadError_InvalidOperation(t *testing.T) { - file, err := ioutil.TempFile("", "big_file") + file, err := os.CreateTemp("", "big_file") if err != nil { assert.FailNow(t, "temp file creation produced an error", err) } @@ -190,8 +189,7 @@ func TestUploadOperationUploadError_InvalidOperation(t *testing.T) { // rmFile closes an open descriptor. func rmFile(f *os.File) { - err := os.Remove(f.Name()) - if err != nil { + if err := os.Remove(f.Name()); err != nil { fmt.Println(err) } } diff --git a/examples/util/util.go b/examples/util/util.go index 90909c5..ffdd45c 100644 --- a/examples/util/util.go +++ b/examples/util/util.go @@ -26,8 +26,8 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" + "os" "time" "github.com/cidertool/asc-go/asc" @@ -47,7 +47,7 @@ func TokenConfig() (auth *asc.AuthTransport, err error) { secret = []byte(*privateKey) } else if *privateKeyPath != "" { // Read private key file as []byte - secret, err = ioutil.ReadFile(*privateKeyPath) + secret, err = os.ReadFile(*privateKeyPath) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index 1cacf6e..99d17c6 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cidertool/asc-go -go 1.13 +go 1.16 require ( github.com/cenkalti/backoff/v4 v4.1.0 diff --git a/test/integration/asc_test.go b/test/integration/asc_test.go index 5d20377..c160074 100644 --- a/test/integration/asc_test.go +++ b/test/integration/asc_test.go @@ -24,7 +24,6 @@ package integration import ( "fmt" - "io/ioutil" "os" "time" @@ -58,7 +57,7 @@ func tokenConfig() *asc.AuthTransport { privateKey = []byte(key) } else if keyPath := os.Getenv(envPrivateKeyPath); keyPath != "" { // Read private key file as []byte - privateKey, err = ioutil.ReadFile(keyPath) + privateKey, err = os.ReadFile(keyPath) if err != nil { fmt.Println(err) return nil