Skip to content

refactor: reduce code duplication through cleanup#8

Merged
knight42 merged 1 commit intov2from
refactor
Nov 11, 2025
Merged

refactor: reduce code duplication through cleanup#8
knight42 merged 1 commit intov2from
refactor

Conversation

@knight42
Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Zack Zeng <jianzeng@meshy.ai>
Copilot AI review requested due to automatic review settings November 11, 2025 23:56
@knight42 knight42 enabled auto-merge (squash) November 11, 2025 23:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors multipart form file handling by consolidating duplicate code into a single method. The main purpose is to reduce code duplication by moving multipart field writing logic from util.go into a method on the MultipartField struct.

Key changes:

  • Consolidated addMultipartFormField and writeMultipartFormFile functions into a single writeToMultipartWriter method on MultipartField
  • Added a Close method to multipartAndPipeWriter for cleaner resource management
  • Increased buffer size from 512 bytes to 32KB and reused it with io.CopyBuffer for better performance

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
multipart.go Added writeToMultipartWriter method to MultipartField and Close method to multipartAndPipeWriter
util.go Removed addMultipartFormField and writeMultipartFormFile functions and mime/multipart import
request.go Updated to call the new writeToMultipartWriter method instead of addMultipartFormField
client.go Simplified cleanup by calling mpw.Close() instead of closing writers individually
util_test.go Updated tests to use the new method on MultipartField struct

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@knight42 knight42 merged commit 6db34d6 into v2 Nov 11, 2025
7 checks passed
@knight42 knight42 deleted the refactor branch November 11, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants