accessor

command module
v0.0.0-...-51ebce2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

做了一个简单的go generate工具,从go官方工具stringer修改而来,为结构体生成setter和getter。

结构体中字段首字母大写默认可读可写,小写则默认只读。

可以添加access的tag,控制访问属性r表示读,w表示写,用逗号分隔。

用法

go get gitee.com/dwdcth/accessor 添加 go:generate accessor -type=Type1,Type2
Type1,Type2表示需要生成的类型,用逗号分隔

//go:generate  accessor -type=Foo,Bar

package foobar

type Foo struct {
	ReadWrite int  `access:"r,w"`
    Write int `access:"w"`
}

type Bar struct {
	ReadWrite int
    read int
}

会生成两个文件,foo_accessor.go 和 bar_accessor.go foo_accessor.go

// Code generated by "accessor -type=Foo,Bar"; DO NOT EDIT.

package foobar

func (f *Foo) SetReadWrite(param int) {
	f.ReadWrite = param
}
func (f *Foo) GetReadWrite() int {
	return f.ReadWrite
}
func (f *Foo) SetWrite(param int) {
	f.Write = param
}

bar_accessor.go

// Code generated by "accessor -type=Foo,Bar"; DO NOT EDIT.

package foobar

func (b *Bar) GetReadWrite() int {
	return b.ReadWrite
}
func (b *Bar) SetReadWrite(param int) {
	b.ReadWrite = param
}
func (b *Bar) Getread() int {
	return b.read
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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