https://github.com/deloz/sid
The main purpose of SID is to seamlessly convert between a JSON-formatted string representation of an ID and its uint64 counterpart when interacting with a database.
https://github.com/deloz/sid
large-number uint64
Last synced: 6 days ago
JSON representation
The main purpose of SID is to seamlessly convert between a JSON-formatted string representation of an ID and its uint64 counterpart when interacting with a database.
- Host: GitHub
- URL: https://github.com/deloz/sid
- Owner: deloz
- License: mit
- Created: 2024-04-05T12:37:38.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-07T07:12:16.000Z (7 months ago)
- Last Synced: 2025-07-07T08:27:26.712Z (7 months ago)
- Topics: large-number, uint64
- Language: Go
- Homepage:
- Size: 49.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SID
The main purpose of SID is to seamlessly convert between a JSON-formatted string representation of an ID and its int64 counterpart when interacting with a database.
## Installation
You can install SID using `go get`:
```bash
go get -u -v github.com/deloz/sid
```
## Usage
Here's a basic example of how to use SID:
```go
package main
import (
"encoding/json"
"fmt"
"github.com/deloz/sid"
)
func main() {
// Create a new ID
id := sid.New(18283195028008204)
// Print the ID as a string
fmt.Println("ID:", id.String())
// Check if the ID is zero
fmt.Println("IsZero:", id.IsZero())
// Marshal the ID to JSON
jsonData, _ := json.Marshal(id)
fmt.Println("JSON:", string(jsonData))
// Unmarshal the ID from JSON
var newID sid.ID
_ = json.Unmarshal(jsonData, &newID)
fmt.Println("Unmarshaled ID:", newID)
}
```
[[play](https://go.dev/play/p/Fie93MkAzmq)]
## Features
- Support creation of IDs from `uint64` (up to `math.MaxInt64`), `int64`, and numeric string representations.
- Implement JSON (de)serialization, comparison, and sorting for custom ID types in Go.
## Contributing
Contributions are welcome! If you find a bug or want to propose a new feature, feel free to open an issue or submit a pull request.
## License
SID is licensed under the MIT License. See [LICENSE](LICENSE) for details.