https://github.com/itcomusic/mapo
An golang map where the keys keep the order
https://github.com/itcomusic/mapo
golang json map order
Last synced: about 2 months ago
JSON representation
An golang map where the keys keep the order
- Host: GitHub
- URL: https://github.com/itcomusic/mapo
- Owner: itcomusic
- License: mit
- Created: 2024-07-20T14:29:15.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-20T16:16:41.000Z (almost 2 years ago)
- Last Synced: 2024-07-20T17:34:36.620Z (almost 2 years ago)
- Topics: golang, json, map, order
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Map Order
[![build-img]][build-url]
[![pkg-img]][pkg-url]
[![coverage-img]][coverage-url]
Is a custom implementation of a map in Go that maintains the order of keys as they are added
## Features
- **Order Preservation**: Keys are stored in the order they are added
- **Custom JSON Marshalling**: Implements custom JSON marshalling and unmarshalling to ensure the order of keys is preserved when converting to and from JSON
- **Key Management**: Provides methods to add, delete, and retrieve keys in their maintained order
## Installation
Go version 1.21+
```bash
go get github.com/itcomusic/mapo
```
## Usage
```go
import (
"fmt"
"github.com/itcomusic/mapo"
)
func main() {
m := mapo.New()
m.Set("a", 1)
m.Set("b", 2)
m.Set("c", 3)
fmt.Println(m.Keys()) // [a, b, c]
value, ok := m.Get("a")
fmt.Println(value, ok) // 1, true
m.Delete("c")
b, _ := json.Marshal(m)
fmt.Println(string(b)) // {"a":1,"b":2}
var m2 mapo.Map
_ = json.Unmarshal(b, &m2)
fmt.Println(m2.Keys()) // [a, b]
}
```
## License
[MIT License](LICENSE)
[build-img]: https://github.com/itcomusic/mapo/workflows/build/badge.svg
[build-url]: https://github.com/itcomusic/mapo/actions
[pkg-img]: https://pkg.go.dev/badge/github.com/itcomusic/mapo.svg
[pkg-url]: https://pkg.go.dev/github.com/itcomusic/mapo
[coverage-img]: https://codecov.io/gh/itcomusic/mapo/branch/main/graph/badge.svg
[coverage-url]: https://codecov.io/gh/itcomusic/mapo