本文整理汇总了Golang中encoding.TextUnmarshaler类的典型用法代码示例。如果您正苦于以下问题:Golang TextUnmarshaler类的具体用法?Golang TextUnmarshaler怎么用?Golang TextUnmarshaler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextUnmarshaler类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: unifyText
func unifyText(data interface{}, v encoding.TextUnmarshaler) error {
var s string
switch sdata := data.(type) {
case encoding.TextMarshaler:
text, err := sdata.MarshalText()
if err != nil {
return err
}
s = string(text)
case fmt.Stringer:
s = sdata.String()
case string:
s = sdata
case bool:
s = fmt.Sprintf("%v", sdata)
case int64:
s = fmt.Sprintf("%d", sdata)
case float64:
s = fmt.Sprintf("%f", sdata)
default:
return badtype("primitive (string-like)", data)
}
if err := v.UnmarshalText([]byte(s)); err != nil {
return err
}
return nil
}
示例2: RedisParseText
func RedisParseText(res string, obj encoding.TextUnmarshaler, err error) error {
if err != nil {
return err
}
err = obj.UnmarshalText([]byte(res))
return err
}
示例3: parseVnetParam
func parseVnetParam(p string, m encoding.TextUnmarshaler) (vnet string, err error) {
vnet, v, err := splitVnetParam(p)
if err != nil {
return "", fmt.Errorf("Error parsing container network parameter %s: %s", p, err)
}
if err = m.UnmarshalText([]byte(v)); err != nil {
return "", fmt.Errorf("Error parsing container network parameter %s: %s", p, err)
}
return vnet, nil
}
示例4: TestEnumIsTextUnmarshaller
func TestEnumIsTextUnmarshaller(t *testing.T) {
var tm encoding.TextUnmarshaler = thrifttest.NumberzPtr(thrifttest.Numberz_TWO)
err := tm.UnmarshalText([]byte("TWO"))
if err != nil {
t.Fatalf("Unexpected error from UnmarshalText(TWO): %s", err)
}
if *(tm.(*thrifttest.Numberz)) != thrifttest.Numberz_TWO {
t.Errorf("UnmarshalText(TWO) = %s", tm)
}
err = tm.UnmarshalText([]byte("NAN"))
if err == nil {
t.Errorf("Error from UnmarshalText(NAN)")
}
}
示例5: unmarshalTextInterface
// unmarshalTextInterface unmarshals a single XML element into val.
// The chardata contained in the element (but not its children)
// is passed to the text unmarshaler.
func (p *Decoder) unmarshalTextInterface(val encoding.TextUnmarshaler, start *StartElement) error {
var buf []byte
depth := 1
for depth > 0 {
t, err := p.Token()
if err != nil {
return err
}
switch t := t.(type) {
case CharData:
if depth == 1 {
buf = append(buf, t...)
}
case StartElement:
depth++
case EndElement:
depth--
}
}
return val.UnmarshalText(buf)
}
示例6: unmarshalTextInterface
func (p *Decoder) unmarshalTextInterface(pval *plistValue, unmarshalable encoding.TextUnmarshaler) {
err := unmarshalable.UnmarshalText([]byte(pval.value.(string)))
if err != nil {
panic(err)
}
}
示例7: DecTextUnmarshal
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
fnerr := tm.UnmarshalText(f.d.d.DecodeBytes(f.d.b[:], true, true))
if fnerr != nil {
panic(fnerr)
}
}