go-codegen

command module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: MIT Imports: 11 Imported by: 0

README

Go Report Card Coverage

go-codegen

With a lack of templates some of the gophers really miss them... Yet another attempt of code generaton in Golang.

Testing

make test # generates code and runs tests

Install

make install

Usage

# Prints help
$ go-codegen -h
Generics
Usage
# Outputs built-in string to int map implementation to stdout
go-codegen generic -t=hashmap string int

# Reads generic source from file pkg/generic/list/list.go and outputs typed implementation to stdout
go-codegen generic -f pkg/generic/list/list.go string

# More help on available built-ins and other command line params
go-codegen help generic

Generics are implemented by parsing an input go source file into an AST and substituting predefined "generic" types. Currently only a fixed list of such types is supported: T0, T1, ..., T5. The advantage of such approach as the generic implementation(input source) is the correct go source that can be tested. See build-ins as examples of how to define a generic type. See test code for more examples.

Immutables
Usage
# Gets a .go source file with defined interfaces and outputs implementation along with builder class to create instances
go-codegen --pkg=model immutable -f tests/immutable/model/model.go

An experiment. Inspired by Java Immutables. See more examples in test code.

Constructor

Generates constructor function for struct. More details see here.

Impl

Generates interface implementations stubs. More details see here.

Nice to have

  • Integration with gen

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
constructor
Package constructor provides code generator to generate New...
Package constructor provides code generator to generate New...
generic
Package generic provides code generator that takes go sources of a generic-like go code and generates concrete implementation by substituting predefined type variables (T1,.., T5) to a given type names
Package generic provides code generator that takes go sources of a generic-like go code and generates concrete implementation by substituting predefined type variables (T1,.., T5) to a given type names
generic/converter
Package converter provides a built-in implementation of generic routines for collection based conversion.
Package converter provides a built-in implementation of generic routines for collection based conversion.
generic/hashmap
Package hashmap provides a built-in implementation of a generic map
Package hashmap provides a built-in implementation of a generic map
generic/iterator
Package iterator provides a built-in implementation of an ideomatic generic iterator
Package iterator provides a built-in implementation of an ideomatic generic iterator
generic/list
Package list provides a built-in implementation of a generic list
Package list provides a built-in implementation of a generic list
generic/set
Package set provides a built-in implementation of a generic set
Package set provides a built-in implementation of a generic set
immutable
Package immutable provides code generator to generate immmutable-like objects and builders for them
Package immutable provides code generator to generate immmutable-like objects and builders for them
impl
Package impl provides code generator to generate interface implementations
Package impl provides code generator to generate interface implementations
testutil
Package testutil provides various utils to test generated code
Package testutil provides various utils to test generated code
tests

Jump to

Keyboard shortcuts

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