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

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

示例1: query

func (ec2 *EC2) query(params map[string]string, resp interface{}) error {
    params["Version"] = "2013-02-01"
    params["Timestamp"] = timeNow().In(time.UTC).Format(time.RFC3339)
    endpoint, err := url.Parse(ec2.Region.EC2Endpoint)
    if err != nil {
        return err
    }
    if endpoint.Path == "" {
        endpoint.Path = "/"
    }
    sign(ec2.Auth, "GET", endpoint.Path, params, endpoint.Host)
    endpoint.RawQuery = multimap(params).Encode()
    if debug {
        log.Printf("get { %v } -> {\n", endpoint.String())
    }
    r, err := http.Get(endpoint.String())
    if err != nil {
        return err
    }
    defer r.Body.Close()

    if debug {
        dump, _ := httputil.DumpResponse(r, true)
        log.Printf("response:\n")
        log.Printf("%v\n}\n", string(dump))
    }
    if r.StatusCode != 200 {
        return buildError(r)
    }
    err = xml.NewDecoder(r.Body).Decode(resp)
    return err
}

开发者ID:rgarcia,项目名称:goamz,代码行数:32,代码来源:ec2.go

示例2: names

// Returns the root node of a tree of valid element names
func names(rdr io.Reader) *name {
    var n = new(name)

    ns := make(map[string]bool)

    decoder := xml.NewDecoder(rdr)
    decoder.Strict = false

    for tok, err := decoder.RawToken(); err != io.EOF; tok, err = decoder.RawToken() {
        // if it breaks, try again!
        if err != nil {
            decoder = xml.NewDecoder(rdr)
            decoder.Strict = false
            continue
        }
        switch el := tok.(type) {
        case xml.StartElement:
            if _, ok := ns[el.Name.Local]; !ok {
                ns[el.Name.Local] = false
            }
        case xml.EndElement:
            if _, ok := ns[el.Name.Local]; ok {
                ns[el.Name.Local] = true
            }
        }
    }
    for k, v := range ns {
        if v {
            n.add([]byte(k))
        }
    }
    // add the XML declaration to the list of valid names (a bit of a hack)
    n.add([]byte("?xml version=\"1.0\"?"))
    return n
}

开发者ID:richardlehane,项目名称:xmltool,代码行数:36,代码来源:fix.go

示例3: respIsOk

func respIsOk(sVueResp *SVUEResponse, expectedElement string) (*xml.Decoder, error) {
    d := xml.NewDecoder(strings.NewReader(sVueResp.Result))

TokenLoop:
    for {
        t, err := d.Token()

        if err == io.EOF {
            return nil, SVUEError{
                OrigError: err,
                Code:      DecodingError,
            }
        }

        if _t, ok := t.(xml.StartElement); ok {
            switch _t.Name.Local {
            case expectedElement:
                break TokenLoop
            case "RT_ERROR":
                return nil, decodeRespError(sVueResp)
            default:
                continue TokenLoop
            }
        } else {
            continue
        }
    }

    return xml.NewDecoder(strings.NewReader(sVueResp.Result)), nil
}

开发者ID:jac0,项目名称:govue,代码行数:30,代码来源:decode_xml.go

示例4: loadConfig

func loadConfig(dirName string) (*objects.Core, error) {
    dir, err := os.Open(os.ExpandEnv(dirName))
    if err != nil {
        return nil, err
    }
    s, err := dir.Stat()
    if err != nil {
        return nil, err
    }
    cfg := &objects.Core{}
    if !s.IsDir() {
        decoder := xml.NewDecoder(dir)
        err = decoder.Decode(&cfg)
        return cfg, err
    }

    files, err := dir.Readdir(-1)
    if err != nil {
        return nil, err
    }
    sort.Sort(FilesByName(files))
    for _, fInfo := range files {
        file, err := os.Open(dirName + fInfo.Name())
        if err != nil {
            return nil, err
        }
        decoder := xml.NewDecoder(file)
        err = decoder.Decode(&cfg)
        if err != nil {
            return nil, fmt.Errorf("Decoding %s: %s", fInfo.Name(), err.Error())
        }
    }

    return cfg, nil
}

开发者ID:daemonl,项目名称:informer,代码行数:35,代码来源:informer.go

示例5: startStream

// startStream will start a new XML decoder for the connection, signal the start of a stream to the server and verify that the server has
// also started the stream; if o.Debug is true, startStream will tee decoded XML data to stderr.  The features advertised by the server
// will be returned.
func (c *Client) startStream(o *Options, domain string) (*streamFeatures, error) {
    if o.Debug {
        c.p = xml.NewDecoder(tee{c.conn, os.Stderr})
    } else {
        c.p = xml.NewDecoder(c.conn)
    }

    _, err := fmt.Fprintf(c.conn, "<?xml version='1.0'?>\n"+
        "<stream:stream to='%s' xmlns='%s'\n"+
        " xmlns:stream='%s' version='1.0'>\n",
        xmlEscape(domain), nsClient, nsStream)
    if err != nil {
        return nil, err
    }

    // We expect the server to start a <stream>.
    se, err := nextStart(c.p)
    if err != nil {
        return nil, err
    }
    if se.Name.Space != nsStream || se.Name.Local != "stream" {
        return nil, fmt.Errorf("expected <stream> but got <%v> in %v", se.Name.Local, se.Name.Space)
    }

    // Now we're in the stream and can use Unmarshal.
    // Next message should be <features> to tell us authentication options.
    // See section 4.6 in RFC 3920.
    f := new(streamFeatures)
    if err = c.p.DecodeElement(f, nil); err != nil {
        return f, errors.New("unmarshal <features>: " + err.Error())
    }
    return f, nil
}

开发者ID:marswang,项目名称:go-xmpp,代码行数:36,代码来源:xmpp.go

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