From d74f4f4a442ce692bf51060e21ecb5a54901fab1 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 17 Mar 2017 16:31:34 +0100 Subject: [PATCH] README/golint: improve readme and make golint happy License: MIT Signed-off-by: Hector Sanjuan --- README.md | 21 +++++++++++++++++++-- multibase.go | 9 +++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f49eb6d..8f7c7f0 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,34 @@ [![Travis CI](https://img.shields.io/travis/multiformats/go-multibase.svg?style=flat-square&branch=master)](https://travis-ci.org/multiformats/go-multibase) [![codecov.io](https://img.shields.io/codecov/c/github/multiformats/go-multibase.svg?style=flat-square&branch=master)](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 +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 diff --git a/multibase.go b/multibase.go index 9746737..8e493e4 100644 --- a/multibase.go +++ b/multibase.go @@ -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 (). 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")