All Projects → globusdigital → Deep Copy

globusdigital / Deep Copy

Licence: bsd-3-clause
Deep copy generator

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Deep Copy

Swiftcolorgen
A tool that generate code for Swift projects, designed to improve the maintainability of UIColors
Stars: ✭ 152 (+85.37%)
Mutual labels:  generator, code-generator
Protoc Gen Gotemplate
📂 generic protocol generator based on golang's text/template (grpc/protobuf)
Stars: ✭ 284 (+246.34%)
Mutual labels:  generator, code-generator
Api Generator
PHP-code generator for Laravel framework, with complete support of JSON-API data format
Stars: ✭ 244 (+197.56%)
Mutual labels:  generator, code-generator
Datamodel Code Generator
Pydantic model generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
Stars: ✭ 393 (+379.27%)
Mutual labels:  generator, code-generator
Go On Rails
🚄 Use Rails to Develop or Generate a Golang Application.
Stars: ✭ 275 (+235.37%)
Mutual labels:  generator, code-generator
Laravel Code Generator
An intelligent code generator for Laravel framework that will save you time! This awesome tool will help you generate resources like views, controllers, routes, migrations, languages and/or form-requests! It is extremely flexible and customizable to cover many on the use cases. It is shipped with cross-browsers compatible template, along with a client-side validation to modernize your application.
Stars: ✭ 485 (+491.46%)
Mutual labels:  generator, code-generator
Mmarkdown
Interpret mmd fenced code blocks in a markdown file and generate a cooler version of it.
Stars: ✭ 67 (-18.29%)
Mutual labels:  generator
Gp Vue Boilerplate
Grabarz & Partner Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites with vuejs.
Stars: ✭ 71 (-13.41%)
Mutual labels:  generator
Guaka
The smartest and most beautiful (POSIX compliant) Command line framework for Swift 🤖
Stars: ✭ 1,145 (+1296.34%)
Mutual labels:  generator
Telosys Cli
Telosys v 3 CLI - Command Line Interface
Stars: ✭ 66 (-19.51%)
Mutual labels:  generator
Jsdoc To Markdown
Generate markdown documentation from jsdoc-annotated javascript
Stars: ✭ 1,199 (+1362.2%)
Mutual labels:  generator
Markdowngenerator
Swift library to programmatically generate Markdown output and files
Stars: ✭ 76 (-7.32%)
Mutual labels:  generator
The forge
Our groundbreaking, lightning fast PWA CLI tool
Stars: ✭ 70 (-14.63%)
Mutual labels:  generator
Generator Rn Toolbox
The React Native Generator to bootstrap your apps
Stars: ✭ 1,155 (+1308.54%)
Mutual labels:  generator
Vos backend
vangav open source - backend; a backend generator (generates more than 90% of the code needed for big scale backend services)
Stars: ✭ 71 (-13.41%)
Mutual labels:  generator
Readme Md Generator
📄 CLI that generates beautiful README.md files
Stars: ✭ 9,184 (+11100%)
Mutual labels:  generator
Spicy Proton
Generate a random English adjective-noun word pair in Ruby
Stars: ✭ 76 (-7.32%)
Mutual labels:  generator
Icongenerator
🍱 A macOS app to generate app icons
Stars: ✭ 1,144 (+1295.12%)
Mutual labels:  generator
Invoice It
📃 Generate your orders or your invoices and export them in html, pdf or buffer easily.
Stars: ✭ 69 (-15.85%)
Mutual labels:  generator
Vwgen
Vulnerable Web applications Generator
Stars: ✭ 75 (-8.54%)
Mutual labels:  generator
GitHub Actions: CI Coverage Status GoReportCard

deep-copy

deep-copy is a tool for generating DeepCopy() functions for a given type.

Given a package directory, and a type name that appears in that package, a DeepCopy method will be generated, to create a deep copy of the type value. Members of the type will also be copied deeply, recursively. If a member T of the type has a method DeepCopy() [*]T, that method will be reused. Multiple types can be specified for the given package, by adding more --type parameters.

To specify a pointer receiver for the method, an optional --pointer-receiver boolean flag can be specified. The flag will also govern whether the return type is a pointer as well.

It might also be desirable to skip deeply copying certain fields, slice members, or map members. To achieve that, selectors can be specified in the optional comma-separated --skip flag. Multiple --skip flags can be specified, to match the number of --type flags. For example, given the following type:

type Foo struct {
     J *int
     B Bar
}

type Bar struct {
    I *int
}

Leaving the 'B' field as a shallow copy can be achieved by specifying --skip B. To skip deeply copying the inner 'I' field, one can specify --skip B.I. Slice and Map members can also be skipped, by adding [i] and [k] respectively.

Usage

Pass either path to the folder containing the types or the module name:

deep-copy <flags> /path/to/package/containing/type
deep-copy <flags> github.com/globusdigital/deep-copy
deep-copy <flags> github.com/globusdigital/deep-copy/some/sub/packages

Here is the full set of supported flags:

deep-copy \ 
  [-o /output/path.go] \
  [--pointer-receiver] \
  [--skip Selector1,Selector.Two --skip Selector2[i], Selector.Three[k]] 
  [--type Type1 --type Type2\ \ 
  /path/to/package/containing/type

Example

Given the following types:

package pkg

type Foo struct {
	Map map[string]*Bar
	ch  chan float32
	baz Baz
}

type Bar struct {
	IntV  int
	Slice []string
}

type Baz struct {
	String        string
	StringPointer *string
}

Running deep-copy --type Foo ./path/to/pkg will generate:

// generated by deep-copy --type Foo ./path/to/pkg !DO NOT EDIT!

package pkg

// DeepCopy generates a deep copy of Foo
func (o Foo) DeepCopy() Foo {
	var cp Foo
	cp = o
	if o.Map != nil {
		cp.Map = make(map[string]*Bar, len(o.Map))
		for k, v := range o.Map {
			var cpv *Bar
			if v != nil {
				cpv = new(*Bar)
				*cpv = *v
				if v.Slice != nil {
					cpv.Slice = make([]string, len(v.Slice))
					copy(cpv.Slice, v.Slice)
				}
			}
			cp.Map[k] = cpv
		}
	}
	if o.ch != nil {
		cp.ch = make(chan float32, cap(o.ch))
	}
	if o.baz.StringPointer != nil {
		cp.baz.StringPointer = new(string)
		*cp.baz.StringPointer = *o.baz.StringPointer
	}
	return cp
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].