本文整理汇总了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
}

开发者ID:BREWTAN,项目名称:etcd,代码行数:27,代码来源:decode.go

示例2: RedisParseText

func RedisParseText(res string, obj encoding.TextUnmarshaler, err error) error {
    if err != nil {
        return err
    }
    err = obj.UnmarshalText([]byte(res))
    return err
}

开发者ID:opus-ua,项目名称:beacon-backend,代码行数:7,代码来源:redis.go

示例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
}

开发者ID:kjplatz,项目名称:vic,代码行数:12,代码来源:create.go

示例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)")
    }
}

开发者ID:ConfusedReality,项目名称:pkg_serialization_thrift,代码行数:15,代码来源:encoding_json_test.go

示例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)
}

开发者ID:Xiahl1990,项目名称:go,代码行数:24,代码来源:read.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng