Documentation
¶
Overview ¶
genaccessor is accsessor generator for Go.
```go
type Foo struct {
key string `getter:"[alias,]..." setter:"[alias,]..."`
}
```
with `go generate` command
```go
//go:generate go-genaccessor
```
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-genaccessor/genaccessor"
)
func main() {
targetDir := "../_example"
if err := genaccessor.Run(
targetDir,
func(pkg *ast.Package) io.Writer {
return os.Stdout
},
genaccessor.WithFileFilter(
func(finfo os.FileInfo) bool {
return !strings.HasSuffix(finfo.Name(), "_test.go")
},
),
); err != nil {
log.Fatal(err)
}
}
Output: // Code generated by go-genaccessor; DO NOT EDIT. package example import ( "encoding" ) func (m Person) ID() string { return m.id } func (m Person) Name() string { return m.name } func (m *Person) Rename(s string) { m.name = s } func (m Person) Tags() []string { return m.tags } func (m *Person) SetTags(s []string) { m.tags = s } func (m Person) Text() encoding.TextMarshaler { return m.text } func (m *Person) SetText(s encoding.TextMarshaler) { m.text = s }
Types ¶
Click to show internal directories.
Click to hide internal directories.