Add comments to methods

This commit is contained in:
TeoV
2021-01-07 15:36:25 +02:00
committed by Dan Christian Bogos
parent f1c3ff0113
commit abb6507006
2 changed files with 26 additions and 10 deletions

View File

@@ -67,13 +67,13 @@ func (cI *CostIncrement) Clone() (cIcln *CostIncrement) {
}
}
if cI.Increment != nil {
cIcln.Increment = new(Decimal).Copy(cI.Increment)
cIcln.Increment = cI.Increment.Clone()
}
if cI.FixedFee != nil {
cIcln.FixedFee = new(Decimal).Copy(cI.FixedFee)
cIcln.FixedFee = cI.FixedFee.Clone()
}
if cI.RecurrentFee != nil {
cIcln.RecurrentFee = new(Decimal).Copy(cI.RecurrentFee)
cIcln.RecurrentFee = cI.RecurrentFee.Clone()
}
return
}
@@ -88,7 +88,7 @@ func (uF *UnitFactor) Clone() (untFct *UnitFactor) {
}
}
if uF.Factor != nil {
untFct.Factor = new(Decimal).Copy(uF.Factor)
untFct.Factor = uF.Factor.Clone()
}
return
}
@@ -181,7 +181,7 @@ func (bL *Balance) Clone() (blnc *Balance) {
}
}
if bL.Units != nil {
blnc.Units = new(Decimal).Copy(bL.Units)
blnc.Units = bL.Units.Clone()
}
return
}
@@ -238,6 +238,7 @@ type APIAccountProfile struct {
ThresholdIDs []string
}
// AsAccountProfile convert APIAccountProfile struct to AccountProfile struct
func (ext *APIAccountProfile) AsAccountProfile() (profile *AccountProfile, err error) {
profile = &AccountProfile{
Tenant: ext.Tenant,
@@ -273,6 +274,7 @@ type APIBalance struct {
Units float64
}
// AsBalance convert APIBalance struct to Balance struct
func (ext *APIBalance) AsBalance() (balance *Balance, err error) {
balance = &Balance{
ID: ext.ID,
@@ -314,6 +316,7 @@ type APICostIncrement struct {
RecurrentFee *float64
}
// AsCostIncrement convert APICostIncrement struct to CostIncrement struct
func (ext *APICostIncrement) AsCostIncrement() (cIncr *CostIncrement, err error) {
cIncr = &CostIncrement{
FilterIDs: ext.FilterIDs,
@@ -342,6 +345,7 @@ type APIUnitFactor struct {
Factor float64
}
// AsUnitFactor convert APIUnitFactor struct to UnitFactor struct
func (ext *APIUnitFactor) AsUnitFactor() (uFac *UnitFactor, err error) {
uFac = &UnitFactor{
FilterIDs: ext.FilterIDs,

View File

@@ -54,6 +54,7 @@ type Decimal struct {
*decimal.Big
}
//UnmarshalBinary implements the method for binaryUnmarshal interface for Msgpack encoding
func (d *Decimal) UnmarshalBinary(data []byte) (err error) {
if d == nil {
d = &Decimal{new(decimal.Big)}
@@ -64,6 +65,7 @@ func (d *Decimal) UnmarshalBinary(data []byte) (err error) {
return d.Big.UnmarshalText(data)
}
//MarshalBinary implements the method for binaryMarshal interface for Msgpack encoding
func (d *Decimal) MarshalBinary() ([]byte, error) {
if d.Big == nil {
d.Big = new(decimal.Big)
@@ -71,17 +73,27 @@ func (d *Decimal) MarshalBinary() ([]byte, error) {
return d.Big.MarshalText()
}
//UnmarshalJSON implements the method for jsonUnmarshal for JSON encoding
func (d *Decimal) UnmarshalJSON(data []byte) (err error) {
return d.UnmarshalBinary(data)
if d == nil {
d = &Decimal{new(decimal.Big)}
}
if d.Big == nil {
d.Big = new(decimal.Big)
}
return d.Big.UnmarshalText(data)
}
//MarshalJSON implements the method for jsonMarshal for JSON encoding
func (d *Decimal) MarshalJSON() ([]byte, error) {
x, err := d.MarshalText()
return bytes.Trim(x, `"`), err
}
func (d *Decimal) Copy(d2 *Decimal) *Decimal {
d.Big = new(decimal.Big)
d.Big.Copy(d2.Big)
return d
//Clone return a copy of the Decimal
func (d *Decimal) Clone() (d2 *Decimal) {
d2 = new(Decimal)
d2.Big = new(decimal.Big)
d2.Big.Copy(d.Big)
return
}