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

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

示例1: startVoting

func startVoting() {
    fmt.Println("Start voting!")
    time.Sleep(time.Second * 10)
    // Send you adress to all. In this case it really doesn't matter
    msg := message.NewVoteMessage(myAddress)
    mm, _ := xml.Marshal(msg)
    _, err := writeMulticast.WriteToUDP(mm, multicastAddr)
    check(err)

    // Wait 10 seconds
    c := time.After(time.Second * 10)
    <-c

    // Check if we got any address that is bigger
    for addr, _ := range knownAddresess {
        if addr > myAddress {
            return
        }
    }

    // Become the server if we are the greatest
    msga := message.NewCoordinatorMessage(string(myAddress))
    mmm, _ := xml.Marshal(msga)
    writeMulticast.WriteToUDP(mmm, multicastAddr)
    fmt.Println("NOW I AM BECOME DEATH")
}

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

示例2: completeMultipartUploadRequest

// completeMultipartUploadRequest wrapper creates a new CompleteMultipartUpload request
func (a apiCore) completeMultipartUploadRequest(bucket, object, uploadID string, complete completeMultipartUpload) (*request, error) {
    op := &operation{
        HTTPServer: a.config.Endpoint,
        HTTPMethod: "POST",
        HTTPPath:   separator + bucket + separator + object + "?uploadId=" + uploadID,
    }
    var completeMultipartUploadBytes []byte
    var err error
    switch {
    case a.config.AcceptType == "application/xml":
        completeMultipartUploadBytes, err = xml.Marshal(complete)
    case a.config.AcceptType == "application/json":
        completeMultipartUploadBytes, err = json.Marshal(complete)
    default:
        completeMultipartUploadBytes, err = xml.Marshal(complete)
    }
    if err != nil {
        return nil, err
    }
    completeMultipartUploadBuffer := bytes.NewReader(completeMultipartUploadBytes)
    r, err := newRequest(op, a.config, completeMultipartUploadBuffer)
    if err != nil {
        return nil, err
    }
    r.req.ContentLength = int64(completeMultipartUploadBuffer.Len())
    return r, nil
}

开发者ID:henrylee2cn,项目名称:mc,代码行数:28,代码来源:api-multipart-core.go

示例3: Build

// Build builds an Envelope for the specified SOAP version.
func (bldr *EnvBuilder) Build(version string) (Envelope, error) {
    if !isValidVersion(version) {
        return nil, ErrInvalidVersion
    }

    bdy, err := xml.Marshal(bldr.payload)
    if err != nil {
        return nil, err
    }

    var env Envelope = &Envelope11{BodyElem: Body11{PayloadElem: bdy}, Xmlns: bldr.xmlns}
    if version == V12 {
        env = &Envelope12{BodyElem: Body12{PayloadElem: bdy}, Xmlns: bldr.xmlns}
    }

    if len(bldr.headers) > 0 {
        hdr, err := xml.Marshal(bldr.headers)
        if err != nil {
            return nil, err
        }

        if len(hdr) > 0 {
            env.setHeader(&Header{Content: hdr})
        }
    }

    return env, nil
}

开发者ID:Bridgevine,项目名称:soap,代码行数:29,代码来源:envelope_builder.go

示例4: SetBucketLogging

//
// SetBucketLogging 修改Bucket的日志设置。
//
// OSS为您提供自动保存访问日志记录功能。Bucket的拥有者可以开启访问日志记录功能。当一个bucket开启访问日志记录功能后,
// OSS自动将访问这个bucket的请求日志,以小时为单位,按照固定的命名规则,生成一个Object写入用户指定的bucket中。
// 如果您需要更多,请参看 https://help.aliyun.com/document_detail/oss/user_guide/security_management/logging.html
//
// bucketName   需要记录访问日志的Bucket。
// targetBucket 访问日志记录到的Bucket。
// targetPrefix bucketName中需要存储访问日志记录的object前缀。为空记录所有object的访问日志。
//
// error 操作无错误为nil,非nil为错误信息。
//
func (client Client) SetBucketLogging(bucketName, targetBucket, targetPrefix string,
    isEnable bool) error {
    var err error
    var bs []byte
    if isEnable {
        lxml := LoggingXML{}
        lxml.LoggingEnabled.TargetBucket = targetBucket
        lxml.LoggingEnabled.TargetPrefix = targetPrefix
        bs, err = xml.Marshal(lxml)
    } else {
        lxml := loggingXMLEmpty{}
        bs, err = xml.Marshal(lxml)
    }

    if err != nil {
        return err
    }

    buffer := new(bytes.Buffer)
    buffer.Write(bs)
    fmt.Println(isEnable, "; xml: ", string(bs))

    contentType := http.DetectContentType(buffer.Bytes())
    headers := map[string]string{}
    headers[HTTPHeaderContentType] = contentType

    resp, err := client.do("PUT", bucketName, "logging", "logging", headers, buffer)
    if err != nil {
        return err
    }
    defer resp.body.Close()
    return checkRespCode(resp.statusCode, []int{http.StatusOK})
}

开发者ID:pombredanne,项目名称:dockyard,代码行数:46,代码来源:client.go

示例5: handleConnection

func handleConnection(conn net.Conn) {

    b := xml.NewDecoder(conn)
    fmt.Fprintf(conn, `<?xml version='1.0'?>
        <stream:stream
            from='localhost'
            id='abc123'
            to='[email protected]'
            version='1.0'
            xml:lang='en'
            xmlns='jabber:server'
            xmlns:stream='http://etherx.jabber.org/streams'>`)

    fmt.Fprintf(conn, "<stream:features/>")
    for {
        iqData := new(Iq)
        b.Decode(iqData)
        switch iqData.Type {
        case "get":
            r := &Iq{Id: iqData.Id, Type: "result"}
            r.Query = Query{Xmlns: "jabber:iq:auth"}
            output, _ := xml.Marshal(r)
            fmt.Fprintf(conn, string(output))
        case "set":
            // Need to perform auth lookup here
            i := Iq{Id: iqData.Id, Type: "result"}
            output, _ := xml.Marshal(i)
            fmt.Fprintf(conn, string(output))
        default:
            // Nothing
        }
    }

}

开发者ID:GoLangPhilly,项目名称:fireside,代码行数:34,代码来源:core.go

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