feat(binding/go): add write with metadata#7827
Open
ryankert01 wants to merge 1 commit into
Open
Conversation
Member
|
Ping me when it's ready to review :) @ryankert01 |
4e696a7 to
a5ce0be
Compare
a5ce0be to
a6348d2
Compare
Member
Author
|
it ok now! cc @dentiny |
dentiny
reviewed
Jun 29, 2026
| meta, err := w.CloseWithMetadata() | ||
| assert.Nil(err, "close with metadata must succeed") | ||
| assert.NotNil(meta, "returned metadata must not be nil") | ||
| assert.Equal(uint64(len(content)), meta.ContentLength(), "writer close metadata content length") |
Member
There was a problem hiding this comment.
I'm not sure if it's proper to assert on content length, based on the doc, the return value could be 0 depending on the storage backend.
| meta, err := op.WriteWithMetadata(path, content) | ||
| assert.Nil(err, "write with metadata must succeed") | ||
| assert.NotNil(meta, "returned metadata must not be nil") | ||
| assert.Equal(uint64(size), meta.ContentLength(), "write metadata content length") |
| // WriteWithMetadata is a wrapper around the C-binding function | ||
| // `opendal_operator_write_with_metadata`. Which fields of the returned Metadata | ||
| // are populated depends on the service. | ||
| func (op *Operator) WriteWithMetadata(path string, data []byte, opts ...WithWriteFn) (*Metadata, error) { |
Member
There was a problem hiding this comment.
Hi @yuchanns I'm wondering if you think it better to add a new API, or we could break current Write API and return metadata?
I kinda prefer to update the return value for Write API:
- Current go binding is not finalized -- we need at least context as the first argument for all APIs
- One single interface is (1) more clear; (2) stick to rust API
Member
Author
There was a problem hiding this comment.
Thanks for the context. Gotcha! Since go bindings not finalized we can do that.
94f4486 to
4694896
Compare
Expose the written object's metadata (etag, version, last modified, content length) from the Go binding's write path, matching the Rust core and the Python binding which already return Metadata from write. Operator.Write and Writer.Close now return (*Metadata, error) instead of only error. This is a deliberate breaking change to the Go binding's public API, agreed on the PR thread: the binding is not yet finalized, and a single metadata-returning interface is clearer and mirrors the Rust API. The C binding gains the additive functions opendal_operator_write_with_metadata and opendal_writer_close_with_metadata (plus the opendal_result_write struct, mirroring opendal_result_stat); the existing error-only C functions are kept.
4694896 to
26b8394
Compare
yuchanns
approved these changes
Jul 2, 2026
dentiny
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
N/A
Rationale for this change
The Go binding discarded the metadata returned by write operations, so callers
could not read the written object's etag/version/last-modified without a second
Stat. The Rust core and the Python binding already returnMetadatafromwrite; this brings the Go binding in line, additively.
What changes are included in this PR?
opendal_operator_write_with_metadataandopendal_writer_close_with_metadata, plus theopendal_result_writestruct(mirrors
opendal_result_stat); regenerateopendal.h. The existingopendal_operator_write/opendal_writer_closeare left unchanged.Operator.WriteWithMetadata(...) (*Metadata, error)andWriter.CloseWithMetadata() (*Metadata, error).WriteandWriter.Closekeep their error-only signatures (still satisfy
io.WriteCloser).Are there any user-facing changes?
Yes, additive only. Two new methods are added; no existing signatures change, so
existing callers keep compiling. The populated
Metadatafields depend on theservice (e.g. content length is always set; etag/version when supported).
AI Usage Statement
Implemented and reviewed with Claude Code (Claude Opus 4.8).