Merge pull request #15 from multiformats/docs-improvements
README/golint: improve readme and make golint happy
This commit is contained in:
21
README.md
21
README.md
@@ -7,17 +7,34 @@
|
||||
[](https://travis-ci.org/multiformats/go-multibase)
|
||||
[](https://codecov.io/github/multiformats/go-multibase?branch=master)
|
||||
|
||||
> Implementation of [multibase](https://github.com/multiformats/multibase) parser in go
|
||||
> Implementation of [multibase](https://github.com/multiformats/multibase) -self identifying base encodings- in Go.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
`go-multibase` is a standard Go module which can be installed with:
|
||||
|
||||
```sh
|
||||
go get github.com/multiformats/go-multibase
|
||||
```
|
||||
|
||||
Note that `go-multibase` is packaged with Gx, so it is recommended to use Gx to install and use it (see Usage section).
|
||||
|
||||
## Usage
|
||||
|
||||
TODO
|
||||
This module is packaged with [Gx](https://github.com/whyrusleeping/gx). In order to use it in your own project it is recommended that you:
|
||||
|
||||
```sh
|
||||
go get -u github.com/whyrusleeping/gx
|
||||
go get -u github.com/whyrusleeping/gx-go
|
||||
cd <your-project-repository>
|
||||
gx init
|
||||
gx import github.com/multiformats/go-multibase
|
||||
gx install --global
|
||||
gx-go --rewrite
|
||||
```
|
||||
|
||||
Please check [Gx](https://github.com/whyrusleeping/gx) and [Gx-go](https://github.com/whyrusleeping/gx-go) documentation for more information.
|
||||
|
||||
## Maintainers
|
||||
|
||||
|
||||
@@ -9,8 +9,10 @@ import (
|
||||
b32 "github.com/whyrusleeping/base32"
|
||||
)
|
||||
|
||||
// Encoding identifies the type of base-encoding that a multibase is carrying.
|
||||
type Encoding int
|
||||
|
||||
// These are the supported encodings
|
||||
const (
|
||||
Identity = 0x00
|
||||
Base1 = '1'
|
||||
@@ -35,8 +37,13 @@ const (
|
||||
Base64urlPad = 'U'
|
||||
)
|
||||
|
||||
// ErrUnsupportedEncoding is returned when the selected encoding is not known or
|
||||
// implemented.
|
||||
var ErrUnsupportedEncoding = fmt.Errorf("selected encoding not supported")
|
||||
|
||||
// Encode encodes a given byte slice with the selected encoding and returns a
|
||||
// multibase string (<encoding><base-encoded-string>). It will return
|
||||
// an error if the selected base is not known.
|
||||
func Encode(base Encoding, data []byte) (string, error) {
|
||||
switch base {
|
||||
case Identity:
|
||||
@@ -65,6 +72,8 @@ func Encode(base Encoding, data []byte) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Decode takes a multibase string and decodes into a bytes buffer.
|
||||
// It will return an error if the selected base is not known.
|
||||
func Decode(data string) (Encoding, []byte, error) {
|
||||
if len(data) == 0 {
|
||||
return 0, nil, fmt.Errorf("cannot decode multibase for zero length string")
|
||||
|
||||
Reference in New Issue
Block a user