genaccessor

package
v0.0.0-...-b0af978 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: MIT Imports: 10 Imported by: 0

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

func Run(targetDir string, newWriter func(pkg *ast.Package) io.Writer, opts ...Option) error
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

type Option

type Option func(o *option)

func WithFileFilter

func WithFileFilter(fileFilter func(finfo os.FileInfo) bool) Option

func WithGeneratorName

func WithGeneratorName(generatorName string) Option

Jump to

Keyboard shortcuts

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