An open API service indexing awesome lists of open source software.

https://github.com/reiver/go-hashuri

Parses Hash URIs, for the Go programming language.
https://github.com/reiver/go-hashuri

content-addressed content-addressing hash-uri uri-parser

Last synced: 2 months ago
JSON representation

Parses Hash URIs, for the Go programming language.

Awesome Lists containing this project

README

        

# go-hashuri

Package **hashuri** parses Hash URIs, for the Go programming language.

And works seemlessly with the Go built-in packages: `"database/sql"`, `"fmt"`, `"encoding/json"`.

## Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-hashuri

[![GoDoc](https://godoc.org/github.com/reiver/go-hashuri?status.svg)](https://godoc.org/github.com/reiver/go-hashuri)

## Hash URI Examples

Hash URIs often look like this:

```
hash://sha256/0ba904eae8773b70c75333db4de2f3ac45a8ad4ddba1b242f0b3cfc199391dd8
\__/ \____/ \______________________________________________________________/
| | |
scheme algorithm hash
```

But, more generally, can look like this:

```
hash://sha256/0ba904eae8773b70c75333db4de2f3ac45a8ad4ddba1b242f0b3cfc199391dd8?apple=one&banana=۲&cherry=3#over-there
\__/ \____/ \______________________________________________________________/ \_________________________/ \________/
| | | | |
scheme algorithm hash query fragment
```

## Go Example

Basic usage of this package looks like this:

```go
import "github.com/reiver/go-hashuri"

var hashURI string = "hash://sha256/0ba904eae8773b70c75333db4de2f3ac45a8ad4ddba1b242f0b3cfc199391dd8"

var parsedHashURI hashuri.Type

if err := hashuri.Parse(&parsedHashURI, hashURI); nil != err {
return err
}

fmt.Printf("Hash URI algorithm: %q \n", parsedHashURI.Algorithm) // Hash URI algorithm: "sha256"
fmt.Printf("Hash URI hash: %q \n", parsedHashURI.Hash) // Hash URI hash: "0ba904eae8773b70c75333db4de2f3ac45a8ad4ddba1b242f0b3cfc199391dd8"
fmt.Printf("Hash URI raw query: %q \n", parsedHashURI.RawQuery) // Hash URI raw query: ""
fmt.Printf("Hash URI fragment: %q \n", parsedHashURI.Fragment) // Hash URI fragment: ""
```

## See Also

The **Hash URI** specification can be found at: https://github.com/hash-uri/hash-uri