Documentation ¶
Overview ¶
genconstructor is constructor generator for Go.
```go
//genconstructor type Foo struct { key string `required:"[constValue]"` }
```
with `go generate` command
```go
//go:generate go-genconstructor
```
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Example ¶
package main import ( "go/ast" "io" "log" "os" "strings" "github.com/hori-ryota/go-genconstructor/genconstructor" ) func main() { targetDir := "../_example" if err := genconstructor.Run( targetDir, func(pkg *ast.Package) io.Writer { return os.Stdout }, genconstructor.WithFileFilter( func(finfo os.FileInfo) bool { return !strings.HasSuffix(finfo.Name(), "_test.go") }, ), ); err != nil { log.Fatal(err) } }
Output: // Code generated by go-genconstructor; DO NOT EDIT. package example import ( "time" ) func NewPerson( id string, name string, ) Person { return Person{ id: id, name: name, createdAt: time.Now(), } } func NewPersonService( id string, ) *PersonService { return &PersonService{ id: id, } }
Types ¶
Click to show internal directories.
Click to hide internal directories.