Documentation ¶
Overview ¶
go-atomicvalue Generates Go code using a package as a generic template for atomic.Value. Given the name of a atomic.Value type T , and the name of a type Value go-atomicvalue will create a new self-contained Go source file implementing
func (m *T) Store(value Value) func (m *T) Load() Value
The file is created in the same package and directory as the package that defines T, Key. It has helpful defaults designed for use with go generate.
For example, given this snippet,
package painkiller import "sync/atomic" type Pill atomic.Value
running this command
go-atomicvalue -type=Pill<time.Time>
in the same directory will create the file pill_atomicvalue.go, in package painkiller, containing a definition of
func (m *Pill) Store(value time.Time) func (m *Pill) Load() time.Time
Typically this process would be run using go generate, like this:
//go:generate go-atomicvalue -type=Pill<int> //go:generate go-atomicvalue -type=Pill<*string> //go:generate go-atomicvalue -type=Pill<time.Time> //go:generate go-atomicvalue -type=Pill<*encoding/json.Token>
With no arguments, it processes the package in the current directory. Otherwise, the arguments must name a single directory holding a Go package or a set of Go source files that represent a single Go package.
The -type flag accepts a comma-separated list of types so a single run can generate methods for multiple types. The default output file is t_string.go, where t is the lower-cased name of the first type listed. It can be overridden with the -output flag.