Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stirby/mapgen
Generate thread-safe, type-safe Go maps
https://github.com/stirby/mapgen
code-generation concurrent-map golang map mapgen threadsafe
Last synced: 3 months ago
JSON representation
Generate thread-safe, type-safe Go maps
- Host: GitHub
- URL: https://github.com/stirby/mapgen
- Owner: stirby
- License: mit
- Created: 2017-06-16T04:22:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-19T22:21:11.000Z (over 1 year ago)
- Last Synced: 2024-10-03T12:30:06.434Z (3 months ago)
- Topics: code-generation, concurrent-map, golang, map, mapgen, threadsafe
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 40
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> **Note**
> As of Go 1.18, just use generics.---
# mapgen
A tool which generates thread safe maps for Go.
Features:
- Supports any key/value pair supported by Go's native maps
- Allows complex operations via `Lock()` and `Unlock()`
- Generated code conforms to `golint` and `gofmt`
- Allows custom types
- Sensible default file name and map name
- Optionally generates using `sync.RWMutex`Generated example located in `examples/`
## Install
`go get -u github.com/s-kirby/mapgen/cmd/mapgen`
## Usage
Create string -> int map:
```bash
$ mapgen string/int
Wrote string_int_map_gen.go
```Create string -> *bytes.Buffer map using a read-write mutex:
```bash
$ mapgen --rwmu string/*bytes.Buffer
Wrote string_buffer_map_gen.go
```Help:
```
usage: mapgen [] []Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
-p, --pkg="." package name
-v, --verbose highly descriptive output
-f, --file=FILE output file name
--rwmu Use RWMutexArgs:
Key and value types, e.g `string/int`
[] name of generated type
```