mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 09:14:27 +08:00
use reader label charset reader for xml deserializing
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
package exchangerates
|
package exchangerates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/html/charset"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/log"
|
"github.com/mayswind/ezbookkeeping/pkg/log"
|
||||||
@@ -127,8 +130,11 @@ func (e *BankOfIsraelDataSource) GetRequestUrls() []string {
|
|||||||
|
|
||||||
// Parse returns the common response entity according to the bank of Israel data source raw response
|
// Parse returns the common response entity according to the bank of Israel data source raw response
|
||||||
func (e *BankOfIsraelDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
func (e *BankOfIsraelDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
||||||
|
xmlDecoder := xml.NewDecoder(bytes.NewReader(content))
|
||||||
|
xmlDecoder.CharsetReader = charset.NewReaderLabel
|
||||||
|
|
||||||
bankOfIsraelData := &BankOfIsraelExchangeRateData{}
|
bankOfIsraelData := &BankOfIsraelExchangeRateData{}
|
||||||
err := xml.Unmarshal(content, bankOfIsraelData)
|
err := xmlDecoder.Decode(bankOfIsraelData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[bank_of_israel_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
log.Errorf(c, "[bank_of_israel_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package exchangerates
|
package exchangerates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/html/charset"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/log"
|
"github.com/mayswind/ezbookkeeping/pkg/log"
|
||||||
@@ -135,8 +138,11 @@ func (e *DanmarksNationalbankDataSource) GetRequestUrls() []string {
|
|||||||
|
|
||||||
// Parse returns the common response entity according to the Danmarks Nationalbank data source raw response
|
// Parse returns the common response entity according to the Danmarks Nationalbank data source raw response
|
||||||
func (e *DanmarksNationalbankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
func (e *DanmarksNationalbankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
||||||
|
xmlDecoder := xml.NewDecoder(bytes.NewReader(content))
|
||||||
|
xmlDecoder.CharsetReader = charset.NewReaderLabel
|
||||||
|
|
||||||
danmarksNationalbankData := &DanmarksNationalbankExchangeRateData{}
|
danmarksNationalbankData := &DanmarksNationalbankExchangeRateData{}
|
||||||
err := xml.Unmarshal(content, danmarksNationalbankData)
|
err := xmlDecoder.Decode(danmarksNationalbankData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[danmarks_national_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
log.Errorf(c, "[danmarks_national_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package exchangerates
|
package exchangerates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/html/charset"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/log"
|
"github.com/mayswind/ezbookkeeping/pkg/log"
|
||||||
@@ -114,8 +117,11 @@ func (e *EuroCentralBankDataSource) GetRequestUrls() []string {
|
|||||||
|
|
||||||
// Parse returns the common response entity according to the euro central bank data source raw response
|
// Parse returns the common response entity according to the euro central bank data source raw response
|
||||||
func (e *EuroCentralBankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
func (e *EuroCentralBankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
||||||
|
xmlDecoder := xml.NewDecoder(bytes.NewReader(content))
|
||||||
|
xmlDecoder.CharsetReader = charset.NewReaderLabel
|
||||||
|
|
||||||
euroCentralBankData := &EuroCentralBankExchangeRateData{}
|
euroCentralBankData := &EuroCentralBankExchangeRateData{}
|
||||||
err := xml.Unmarshal(content, euroCentralBankData)
|
err := xmlDecoder.Decode(euroCentralBankData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[euro_central_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
log.Errorf(c, "[euro_central_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
||||||
|
|||||||
@@ -127,11 +127,11 @@ func (e *NationalBankOfPolandDataSource) GetRequestUrls() []string {
|
|||||||
|
|
||||||
// Parse returns the common response entity according to the National Bank of Poland data source raw response
|
// Parse returns the common response entity according to the National Bank of Poland data source raw response
|
||||||
func (e *NationalBankOfPolandDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
func (e *NationalBankOfPolandDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
||||||
nationalBankOfPolandData := &NationalBankOfPolandExchangeRateData{}
|
|
||||||
|
|
||||||
xmlDecoder := xml.NewDecoder(bytes.NewReader(content))
|
xmlDecoder := xml.NewDecoder(bytes.NewReader(content))
|
||||||
xmlDecoder.CharsetReader = charset.NewReaderLabel
|
xmlDecoder.CharsetReader = charset.NewReaderLabel
|
||||||
err := xmlDecoder.Decode(&nationalBankOfPolandData)
|
|
||||||
|
nationalBankOfPolandData := &NationalBankOfPolandExchangeRateData{}
|
||||||
|
err := xmlDecoder.Decode(nationalBankOfPolandData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[national_bank_of_poland_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
log.Errorf(c, "[national_bank_of_poland_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package exchangerates
|
package exchangerates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/html/charset"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/log"
|
"github.com/mayswind/ezbookkeeping/pkg/log"
|
||||||
@@ -163,8 +166,11 @@ func (e *NationalBankOfRomaniaDataSource) GetRequestUrls() []string {
|
|||||||
|
|
||||||
// Parse returns the common response entity according to the national bank of Romania data source raw response
|
// Parse returns the common response entity according to the national bank of Romania data source raw response
|
||||||
func (e *NationalBankOfRomaniaDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
func (e *NationalBankOfRomaniaDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
||||||
|
xmlDecoder := xml.NewDecoder(bytes.NewReader(content))
|
||||||
|
xmlDecoder.CharsetReader = charset.NewReaderLabel
|
||||||
|
|
||||||
nationalBankOfRomaniaData := &NationalBankOfRomaniaExchangeRateData{}
|
nationalBankOfRomaniaData := &NationalBankOfRomaniaExchangeRateData{}
|
||||||
err := xml.Unmarshal(content, nationalBankOfRomaniaData)
|
err := xmlDecoder.Decode(nationalBankOfRomaniaData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[national_bank_of_romania_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
log.Errorf(c, "[national_bank_of_romania_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package exchangerates
|
package exchangerates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/html/charset"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/log"
|
"github.com/mayswind/ezbookkeeping/pkg/log"
|
||||||
@@ -159,8 +162,11 @@ func (e *NorgesBankDataSource) GetRequestUrls() []string {
|
|||||||
|
|
||||||
// Parse returns the common response entity according to the Norges Bank data source raw response
|
// Parse returns the common response entity according to the Norges Bank data source raw response
|
||||||
func (e *NorgesBankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
func (e *NorgesBankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
||||||
|
xmlDecoder := xml.NewDecoder(bytes.NewReader(content))
|
||||||
|
xmlDecoder.CharsetReader = charset.NewReaderLabel
|
||||||
|
|
||||||
norgesBankData := &NorgesBankExchangeRateData{}
|
norgesBankData := &NorgesBankExchangeRateData{}
|
||||||
err := xml.Unmarshal(content, norgesBankData)
|
err := xmlDecoder.Decode(norgesBankData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[norges_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
log.Errorf(c, "[norges_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package exchangerates
|
package exchangerates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/html/charset"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/log"
|
"github.com/mayswind/ezbookkeeping/pkg/log"
|
||||||
@@ -129,8 +132,11 @@ func (e *ReserveBankOfAustraliaDataSource) GetRequestUrls() []string {
|
|||||||
|
|
||||||
// Parse returns the common response entity according to the the reserve bank of Australia data source raw response
|
// Parse returns the common response entity according to the the reserve bank of Australia data source raw response
|
||||||
func (e *ReserveBankOfAustraliaDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
func (e *ReserveBankOfAustraliaDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
||||||
|
xmlDecoder := xml.NewDecoder(bytes.NewReader(content))
|
||||||
|
xmlDecoder.CharsetReader = charset.NewReaderLabel
|
||||||
|
|
||||||
reserveBankOfAustraliaData := &ReserveBankOfAustraliaData{}
|
reserveBankOfAustraliaData := &ReserveBankOfAustraliaData{}
|
||||||
err := xml.Unmarshal(content, reserveBankOfAustraliaData)
|
err := xmlDecoder.Decode(reserveBankOfAustraliaData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[reserve_bank_of_australia_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
log.Errorf(c, "[reserve_bank_of_australia_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package exchangerates
|
package exchangerates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/html/charset"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/log"
|
"github.com/mayswind/ezbookkeeping/pkg/log"
|
||||||
@@ -189,8 +192,11 @@ func (e *SwissNationalBankDataSource) GetRequestUrls() []string {
|
|||||||
|
|
||||||
// Parse returns the common response entity according to the the reserve Swiss National Bank data source raw response
|
// Parse returns the common response entity according to the the reserve Swiss National Bank data source raw response
|
||||||
func (e *SwissNationalBankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
func (e *SwissNationalBankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) {
|
||||||
|
xmlDecoder := xml.NewDecoder(bytes.NewReader(content))
|
||||||
|
xmlDecoder.CharsetReader = charset.NewReaderLabel
|
||||||
|
|
||||||
swissNationalBankData := &SwissNationalBankData{}
|
swissNationalBankData := &SwissNationalBankData{}
|
||||||
err := xml.Unmarshal(content, swissNationalBankData)
|
err := xmlDecoder.Decode(swissNationalBankData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[swiss_national_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
log.Errorf(c, "[swiss_national_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())
|
||||||
|
|||||||
Reference in New Issue
Block a user