https://github.com/ksinica/yamf
Yet-Another-Multi-Format implementation in Go.
https://github.com/ksinica/yamf
bamboo blake2b go hash yamf
Last synced: 8 months ago
JSON representation
Yet-Another-Multi-Format implementation in Go.
- Host: GitHub
- URL: https://github.com/ksinica/yamf
- Owner: ksinica
- License: mit
- Created: 2022-07-26T10:39:25.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-04T17:29:40.000Z (about 3 years ago)
- Last Synced: 2025-01-12T23:27:10.816Z (9 months ago)
- Topics: bamboo, blake2b, go, hash, yamf
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yamf
[](https://godoc.org/github.com/ksinica/yamf)
[Yet-Another-Multi-Format](https://github.com/AljoschaMeyer/yamf-hash) implementation in Go.
#### Warning
This library is a work in progress and does not strive to have an A+ score at the moment. Although, `v0.1.0` should be simple, usable, and self-explanatory enough with fair unit test coverage.#### Example
##### Encode hash to JSON
```go
package mainimport (
"encoding/json"
"os""github.com/ksinica/yamf"
"github.com/ksinica/yamf/hash/blake2b"
)func main() {
hash, _ := blake2b.New()
hash.Write([]byte("Hello world!"))json.NewEncoder(os.Stdout).Encode(struct {
Hash *yamf.TypeValue `json:"hash"`
}{
Hash: yamf.HashToTypeValue(hash),
})
// {"hash":"0008239dad53cf69f358"}
}
```
##### Decode hash from JSON
```go
package mainimport (
"encoding/json""github.com/ksinica/yamf"
_ "github.com/ksinica/yamf/hash/blake2b"
)func main() {
var val struct {
Hash *yamf.TypeValue `json:"hash"`
}json.Unmarshal([]byte(`{"hash":"0008239dad53cf69f358"}`), &val)
hash, _ := yamf.TypeValueToHash(*val.Hash)
hash.Write([]byte("Hello world!"))if !yamf.HashEqual(hash, *val.Hash) {
panic("oh no!")
}
}
```
## LicenseSource code is available under the MIT [License](/LICENSE).