本文整理匯總了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)
}
}