package multibaseimport ()// Encoder is a multibase encoding that is verified to be supported and// supports an Encode method that does not return an errortypeEncoderstruct { enc Encoding}// NewEncoder create a new Encoder from an Encodingfunc ( Encoding) (Encoder, error) { , := EncodingToStr[]if ! {returnEncoder{-1}, fmt.Errorf("unsupported multibase encoding: %d", ) }returnEncoder{}, nil}// MustNewEncoder is like NewEncoder but will panic if the encoding is// invalid.func ( Encoding) Encoder { , := EncodingToStr[]if ! {panic("Unsupported multibase encoding") }returnEncoder{}}// EncoderByName creates an encoder from a string, the string can// either be the multibase name or single character multibase prefixfunc ( string) (Encoder, error) {varEncodingvarbooliflen() == 0 {returnEncoder{-1}, fmt.Errorf("empty multibase encoding") } elseifutf8.RuneCountInString() == 1 { , := utf8.DecodeRuneInString() = Encoding() _, = EncodingToStr[] } else { , = Encodings[] }if ! {returnEncoder{-1}, fmt.Errorf("unsupported multibase encoding: %s", ) }returnEncoder{}, nil}func ( Encoder) () Encoding {return .enc}// Encode encodes the multibase using the given Encoder.func ( Encoder) ( []byte) string { , := Encode(.enc, )if != nil {// should not happenpanic() }return}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.