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

build: bump go version #715

Merged
merged 7 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.20', '1.21']
go-version: ['1.21', '1.22']
fail-fast: true
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
security-events: write
strategy:
matrix:
go-version: ['1.20', '1.21']
go-version: ['1.21', '1.22']
fail-fast: false
steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The ORAS Go library follows [Semantic Versioning](https://semver.org/), where br
The version `2` is actively developed in the [`main`](https://github.com/oras-project/oras-go/tree/main) branch with all new features.

> [!Note]
> The `main` branch follows [Go's Security Policy](https://github.com/golang/go/security/policy) and supports the two latest versions of Go (currently `1.20` and `1.21`).
> The `main` branch follows [Go's Security Policy](https://github.com/golang/go/security/policy) and supports the two latest versions of Go (currently `1.21` and `1.22`).

Examples for common use cases can be found below:

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module oras.land/oras-go/v2

go 1.20
go 1.21

require (
github.com/opencontainers/go-digest v1.0.0
Expand Down
19 changes: 13 additions & 6 deletions internal/ioutil/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ func CopyBuffer(dst io.Writer, src io.Reader, buf []byte, desc ocispec.Descripto

// nopCloserType is the type of `io.NopCloser()`.
var nopCloserType = reflect.TypeOf(io.NopCloser(nil))
var nopCloserWriterToType = reflect.TypeOf(io.NopCloser(struct {
dextrot marked this conversation as resolved.
Show resolved Hide resolved
dextrot marked this conversation as resolved.
Show resolved Hide resolved
io.Reader
io.WriterTo
}{}))

// UnwrapNopCloser unwraps the reader wrapped by `io.NopCloser()`.
// unwrapNopCloser return the underlying reader and true if r is a NopCloser
// else it return false.
dextrot marked this conversation as resolved.
Show resolved Hide resolved
// Similar implementation can be found in the built-in package `net/http`.
// Reference: https://github.com/golang/go/blob/go1.17.6/src/net/http/transfer.go#L423-L425
func UnwrapNopCloser(rc io.Reader) io.Reader {
if reflect.TypeOf(rc) == nopCloserType {
return reflect.ValueOf(rc).Field(0).Interface().(io.Reader)
// Reference: https://github.com/golang/go/blob/go1.22.1/src/net/http/transfer.go#L1090-L1105
func unwrapNopCloser(r io.Reader) (underlyingReader io.Reader, isNopCloser bool) {
dextrot marked this conversation as resolved.
Show resolved Hide resolved
dextrot marked this conversation as resolved.
Show resolved Hide resolved
switch reflect.TypeOf(r) {
case nopCloserType, nopCloserWriterToType:
return reflect.ValueOf(r).Field(0).Interface().(io.Reader), true
default:
return nil, false
dextrot marked this conversation as resolved.
Show resolved Hide resolved
}
return rc
}
Loading