本文整理汇总了Golang中encoding/xml.Unmarshal函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Unmarshal函数的具体用法?Golang Unmarshal怎么用?Golang Unmarshal使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了Unmarshal函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: DecodeClientToClientMessage

func DecodeClientToClientMessage(msg []byte) (Type, *UserToUserPackage, error) {
    var m ClientToClientMessage
    err := xml.Unmarshal(msg, &m)
    if err != nil {
        return UNKNOWN_T, nil, err
    }
    switch m.Type {
    case VOTE:
        var v VoteMessage
        err := xml.Unmarshal(msg, &v)
        if err != nil {
            return UNKNOWN_T, nil, errors.New("Couldn't decode the message: Broadcast or direct message malformed")
        }
        uu := UserToUserPackage{
            VoteMessage: &v,
        }
        return VOTE_T, &uu, nil
    case COORDINATOR:
        var v CoordinatorMessage
        err := xml.Unmarshal(msg, &v)
        if err != nil {
            return UNKNOWN_T, nil, errors.New("Couldn't decode the message: Broadcast or direct message malformed")
        }
        uu := UserToUserPackage{
            CoordinatorMessage: &v,
        }
        return COORDINATOR_T, &uu, nil
    }
    return UNKNOWN_T, nil, errors.New("Couldn't decode the message: No matching type")
}

开发者ID:Madrigal,项目名称:GoUDP,代码行数:30,代码来源:message.go

示例2: RegisterDevice

func RegisterDevice(token string, customData string, userId string,
    userSecret string, region string, applicationArn string) (arn string, err error) {
    values := url.Values{}
    values.Set("Action", "CreatePlatformEndpoint")
    values.Set("CustomUserData", customData)
    values.Set("Token", token)
    values.Set("PlatformApplicationArn", applicationArn)
    values.Set("Timestamp", time.Now().UTC().Format(time.RFC3339))

    response, err := makeRequest("http://sns."+region+".amazonaws.com/",
        values, userId, userSecret, region)

    if err != nil {
        return "", err
    }

    defer response.Body.Close()

    if response.StatusCode != 200 {
        content, _ := ioutil.ReadAll(response.Body)
        var errorResponse aws.ErrorResponse
        xml.Unmarshal(content, &errorResponse)
        return "", errors.New("Unable to register device. " + errorResponse.Error.Code + ": " + errorResponse.Error.Message)
    } else {
        content, _ := ioutil.ReadAll(response.Body)
        var createResponse CreateResponse
        xml.Unmarshal(content, &createResponse)
        return createResponse.CreatePlatformEndpointResult.EndpointArn, nil
    }
}

开发者ID:usmanismail,项目名称:gpns,代码行数:30,代码来源:snsclient.go

示例3: loadCloudFormationResource

func (client *Client) loadCloudFormationResource(action string, params Values, i interface{}) error {
    req, e := client.signedCloudFormationRequest(action, params)

    rsp, e := httpClient.Do(req)
    if e != nil {
        return e
    }
    defer rsp.Body.Close()
    b, e := ioutil.ReadAll(rsp.Body)
    if e != nil {
        return e
    }
    switch rsp.StatusCode {
    case 404:
        return ErrorNotFound
    case 200:
        if i != nil {
            return xml.Unmarshal(b, i)
        }
        return nil
    default:
        ersp := &ErrorResponse{}
        dbg.Printf("ERROR=%q", string(b))
        e = xml.Unmarshal(b, ersp)
        if e != nil {
            return fmt.Errorf("expected status 2xx but got %s (%s)", rsp.Status, string(b))

        }
        if strings.Contains(ersp.Error.Message, "does not exist") {
            return ErrorNotFound
        }
        return fmt.Errorf(ersp.Error.Message)
    }
}

开发者ID:himanshugpt,项目名称:evergreen,代码行数:34,代码来源:main.go

示例4: Analyse

//解析配置文件内容至内存中
func Analyse() error {

    content, err := ioutil.ReadFile("../etc/config.xml")

    if err != nil {
        Log.Error(err)
        return err
    }

    err = xml.Unmarshal(content, &config)
    if err != nil {
        Log.Error(err)
        return err
    }

    content, err = ioutil.ReadFile("../etc/entity.xml")
    err = xml.Unmarshal(content, &entitys)

    if err != nil {
        Log.Error(err)
        return err
    }

    content, err = ioutil.ReadFile("../etc/url.xml")
    err = xml.Unmarshal(content, &urls)

    if err != nil {
        Log.Error(err)
        return err
    }

    return nil
}

开发者ID:huangjq,项目名称:lessgo,代码行数:34,代码来源:lessgo.go

示例5: WexinHandler

func WexinHandler(resp http.ResponseWriter, req *http.Request) {

    log.Println("method:", req.Method)
    if req.Method == "GET" {
        weixinValid(resp, req)
    } else {

        data, err := ioutil.ReadAll(req.Body)
        if nil != err {
            log.Println("read body err:", err)
            return
        }
        log.Println("data:", string(data))

        request := &entry.ReqMessage{}
        er := xml.Unmarshal(data, request)
        if nil != er {
            log.Println("decode body err:", er)
            return
        }

        event := request.Event
        msgType := request.MsgType
        ch := make(chan interface{})
        defer close(ch)
        if "event" == msgType && event == "subscribe" {
            //添加关注事件
            go subEventProcess(*request, ch)

        } else if "event" == msgType && event == "unsubscribe" {
            //取消订阅
            go unsubEventProcess(*request, ch)

        } else if "location" == msgType {
            //地理位置
            var msg entry.LocRequest
            err := xml.Unmarshal(data, &msg)
            if nil != err {
                log.Println("decode txt request body err:", err)
                return
            }

            go locMessageProcess(msg, ch)

        } else {
            var msg entry.TxtRequest
            err := xml.Unmarshal(data, &msg)
            if nil != err {
                log.Println("decode txt request body err:", er)
                return
            }

            go txtMessageProcess(msg, ch)
        }

        brespons, _ := xml.Marshal(<-ch)
        log.Println(string(brespons))
        resp.Write(brespons)
    }
}

开发者ID:houzhenggang,项目名称:weixin-1,代码行数:60,代码来源:weixin.go

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