Как обращаться с заголовками ответа мыла в Голанге - PullRequest
0 голосов
/ 02 октября 2019

Я вызываю api мыла из golang, ответ на api мыла имеет заголовок и тело. Как обработать ответ заголовка в golang

это ответ мыльного API

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header>
        <SessionId xmlns="http://schemas.com/2/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
        <TransactionId xmlns="http://schemas.com/2/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
    </S:Header>
    <S:Body>
        <GetResponse xmlns="http://schemas.ericsson.com/cai3g1.2/">
            <MOAttributes>
                <ilf:getResponseSubscription xmlns:ilf="http://schemas.com/ema/ILF/" publicIdentity="tel:+1234567890">
                    <ilf:publicIdEntry publicIdentity="tel:+1234567890">
                    </ilf:publicIdEntry>
                </ilf:getResponseSubscription>
            </MOAttributes>
        </GetResponse>
    </S:Body>
</S:Envelope>

это моя клиентская структура struct

type SOAPEnvelopeOutput struct {
    XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
    Header  SoapHeaderOutput
    Body    SOAPBodyOutput }

type SOAPBodyOutput struct {
    XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"`
    Content []byte `xml:",innerxml"` }

type SoapHeaderOutput struct {
    XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"`
    Items []byte `xml:",innerxml"` }

Вот код, который я написал: parse:

type GetResponse struct {
    XMLName               xml.Name `xml:"http://schemas.ericsson.com/cai3g1.2/ GetResponse"`
    GetMOAttributes       MOAttributes `xml:"MOAttributes"`
}

type MOAttributes struct {
    XMLName                   xml.Name                `xml:"http://schemas.ericsson.com/cai3g1.2/ MOAttributes"`
    GetResponseSubscription   getResponseSubscription `xml:"ilf:getResponseSubscription"`
}

type getResponseSubscription struct {
    XMLName            xml.Name `xml:"http://schemas.ericsson.com/cai3g1.2/ ilf:getResponseSubscription"`
    GetPublicIdEntry   getPublicIdEntry  `xml:"ilf:publicIdEntry"`
}

type getPublicIdEntry struct {
    XMLName            xml.Name `xml:"http://schemas.ericsson.com/cai3g1.2/ ilf:publicIdEntry"`
    }
...