Yet-Another-Multi-Format implementation in Go.
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.
package main
import (
"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"}
}
package main
import (
"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!")
}
}
Source code is available under the MIT License.