Skip to content

ninibe/atomicmapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

atomicmapper

atomicmapper is a code generation tool for creating high-performance, scalable, frequently read, but infrequently updated maps of strings to any given type map[string]YourType. It is based on Go's atomic.Value read mostly example.

Requires Go 1.4+

usage with go:generate

Install atomicmapper.

go install github.com/ninibe/atomicmapper
# move to $PATH if $GOPATH/bin is not in your $PATH

Add the generate command.

//go:generate atomicmapper -pointer -type Foo
type Foo struct { ... }

Skip the -pointer flag to save entire values. Generate the atomic map code.

go generate myfoopkg

This will create a new foo_atomicmap.go file ready to use.

fooMap := NewFooAtomicMap()
fooMap.Set("myKey", &Foo{}) // save pointer to Foo
foo, ok := fooMap.Get("myKey")  // retrieve pointer
fooMap.Delete("myKey")      // remove pointer from map

All methods are thread-safe while Get is also lock-free. Check the example godoc

usage with gen

See atomic map typewriter

About

code generation of Go atomic maps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages