Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. go-deepcopy

go-deepcopy

MITGov1.7.2

A fast, feature-rich deep-copy library for Go with support for complex type conversions and custom copying behaviors.

GitHubGitHub
130 stars7 forks0 contributors

What is go-deepcopy?

go-deepcopy is a Go library that performs fast and flexible deep copying of data structures. It solves the problem of manually copying complex nested types by providing a reflection-based API that supports copying between different types, custom field mappings, and post-copy hooks.

Target Audience

Go developers working with complex data structures, serialization, or data transformation tasks, especially those needing to copy data between different struct types or convert types during copying.

Value Proposition

Developers choose go-deepcopy for its combination of speed, extensive feature set, and configurability, outperforming many alternative libraries in benchmarks while offering advanced features like zero-to-nil conversion and custom copy methods.

Overview

Fast deep-copy library for Go

Use Cases

Best For

  • Copying data between structs with different field names or types
  • Converting nested data structures during serialization or deserialization
  • Implementing custom copying logic with struct methods
  • Handling embedded structs and inherited fields in copies
  • Setting nil values for zero fields in API responses
  • Performing post-copy transformations with hooks

Not Ideal For

  • Applications where every nanosecond counts and manual struct copying is trivial and maintainable
  • Projects that exclusively copy between identical types without needing field renaming or type conversion
  • Teams that enforce strict compile-time type safety and avoid reflection-based solutions

Pros & Cons

Pros

Benchmark-Leading Performance

In benchmarks, it significantly outperforms popular alternatives like jinzhu/copier and mohae/deepcopy in both speed and memory usage, making it one of the fastest deep-copy libraries available.

Flexible Type Conversion

Supports copying between convertible types (e.g., int to float) and between pointers and values, enabling seamless data transformation without manual code.

Advanced Field Mapping

Uses struct tags to copy between fields with different names, skip fields, or require copying, providing fine-grained control as shown in the field mapping and skip examples.

Extensible Custom Logic

Allows structs to define Copy<field> methods and PostCopy hooks for custom copying and post-processing, adapting to complex business needs with examples in the README.

Cons

Reflection Overhead Inevitable

Despite being fast among libraries, it's still slower than manual copying due to reflection, with benchmarks showing it's about 10-20x slower in some cases, which can impact performance-critical paths.

Configuration Complexity

Requires understanding of struct tags, custom methods, and configuration options, which can be error-prone and increase the learning curve, especially for developers new to reflection-based APIs.

Runtime Type Safety Risks

As a reflection-based library, type mismatches and errors are only caught at runtime, potentially leading to panics if not handled carefully, such as with unexported fields requiring address passing.

Frequently Asked Questions

Quick Stats

Stars130
Forks7
Contributors0
Open Issues0
Last commit7 months ago
CreatedSince 2023

Tags

#deep-copy#copy#conversion#struct-mapping#golang#serialization#reflection#transformation#data-transformation#go#type-conversion#deepcopy#performance

Built With

G
Go

Included in

Go169.1k
Auto-fetched 5 hours ago

Related Projects

DeepcopierDeepcopier

simple struct copying for golang

Stars460
Forks57
Last commit6 years ago
gotypegotype

Golang source code parsing, usage like reflect package

Stars66
Forks9
Last commit14 days ago
copycopy

Package for fast copying structs of different types

Stars51
Forks5
Last commit5 years ago
gpathgpath

gpath is a Go package to access a field by a path using reflect pacakge

Stars41
Forks4
Last commit9 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub