GithubHelp home page GithubHelp logo

accessor's Introduction

Fork from https://gitee.com/dwdcth/accessor.git

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

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

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

用法

go get -u github.com/huzilin/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
}

accessor's People

Watchers

James Cloos avatar Lin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.