constructor

command module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 11 Imported by: 0

README

Constructor

constructor is a Go code generator for creating constructors for your structs. This tool helps you generate constructor functions automatically, saving you time and ensuring consistency across your codebase.

Installation

To install the constructor tool, use go get:

go get github.com/daxartio/constructor

Usage

The constructor tool can be run from the command line with various options. Below are the available options and their descriptions:

Usage of constructor:
  -f string
        A format of the filename. (default "%s_constructor_gen.go")
  -h    Show help.
  -n    No prefix.
  -p string
        Package full path. (default ".")
  -s string
        Match structs name. (comma separated)
  -w    Write generated code.
Options
  • -f string: Specifies the format of the generated filename. By default, the filename format is %s_constructor_gen.go, where %s will be replaced with the name of the struct.
  • -h: Displays help information for the constructor tool.
  • -n: Disables the prefix in the generated constructor function names.
  • -p string: Specifies the full path of the package where the structs are located. The default value is the current directory (.).
  • -s string: Specifies the names of the structs to match, separated by commas.
  • -w: Writes the generated code to the specified file. If this option is not set, the generated code will be printed to the standard output.

Examples

Generate constructors for all structs in the current package and print the result to the standard output:

constructor -p .

Generate constructors for specific structs (User,Order) and write the generated code to files:

constructor -p . -s User,Order -w

Generate constructors without any prefix in the function names:

constructor -p . -n

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL