Ejemplo n.º 1
0
func (self *Converter) ReadEncodedString(input interface{},
	fallback strencoding.Handler) []byte {

	if input == nil {
		panic("Expecting a value (type 'string'), but it's missing")
	}
	str, ok := input.(string)
	if !ok {
		panic(fmt.Sprintf("The given thing of type %T is not a string", input))
	}
	data, err := strencoding.Encode(str, fallback)
	if err != nil {
		panic(err)
	}
	return data
}
Ejemplo n.º 2
0
func (self *Converter) ReadBucketId(input interface{}) bucket.Id {
	if input == nil {
		panic("Expecting a bucket id but value is missing")
	}
	switch input := input.(type) {
	case string:
		bucketIdBinary, err := strencoding.Encode(input, strencoding.Base32)
		if err != nil {
			panic(err)
		}
		return bucket.Id(bucketIdBinary)
	case []byte:
		return bucket.Id(self.ReadBinary(input))
	case bucket.Id:
		return input
	default:
		panic(fmt.Sprintf("Expecting a string or a binary but got a %T", input))
	}
}
Ejemplo n.º 3
0
func StringToElement(str string) (value []byte, err error) {
	return strencoding.Encode(str, strencoding.String)
}