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 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
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
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
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
@@ -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
16 changes: 12 additions & 4 deletions internal/ioutil/io.go
Expand Up @@ -46,13 +46,21 @@ 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))
// nopCloserWriterToType is the type of `io.nopCloserWriterTo`
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
// Reference: https://github.com/golang/go/blob/go1.22.1/src/net/http/transfer.go#L1090-L1105
func UnwrapNopCloser(rc io.Reader) io.Reader {
if reflect.TypeOf(rc) == nopCloserType {
switch reflect.TypeOf(rc) {
case nopCloserType, nopCloserWriterToType:
return reflect.ValueOf(rc).Field(0).Interface().(io.Reader)
default:
return rc
}
return rc
}