Skip to content

Commit

Permalink
Merge branch 'release/v1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Oct 10, 2023
2 parents 22539e8 + 238ad21 commit 1ca9635
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
66 changes: 66 additions & 0 deletions model/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package model

import "strconv"

// Uint64 support string quoted number in json
type Uint64 uint64

// UnmarshalJSON implement json Unmarshal interface
func (u64 *Uint64) UnmarshalJSON(b []byte) (err error) {
if b[0] == '"' && b[len(b)-1] == '"' {
b = b[1 : len(b)-1]
}
i, _ := strconv.ParseUint(string(b), 10, 64)
*u64 = Uint64(i)
return
}

func (u64 Uint64) Value() uint64 {
return uint64(u64)
}

func (u64 Uint64) String() string {
return strconv.FormatUint(uint64(u64), 10)
}

// Int64 support string quoted number in json
type Int64 int64

// UnmarshalJSON implement json Unmarshal interface
func (i64 *Int64) UnmarshalJSON(b []byte) (err error) {
if b[0] == '"' && b[len(b)-1] == '"' {
b = b[1 : len(b)-1]
}
i, _ := strconv.ParseInt(string(b), 10, 64)
*i64 = Int64(i)
return
}

func (i64 Int64) Value() int64 {
return int64(i64)
}

func (i64 Int64) String() string {
return strconv.FormatInt(int64(i64), 10)
}

// Float64 support string quoted number in json
type Float64 float64

// UnmarshalJSON implement json Unmarshal interface
func (f64 *Float64) UnmarshalJSON(b []byte) (err error) {
if b[0] == '"' && b[len(b)-1] == '"' {
b = b[1 : len(b)-1]
}
i, _ := strconv.ParseFloat(string(b), 64)
*f64 = Float64(i)
return
}

func (f64 Float64) Value() float64 {
return float64(f64)
}

func (f64 Float64) String(prec int) string {
return strconv.FormatFloat(float64(64), 'f', prec, 64)
}
7 changes: 5 additions & 2 deletions model/unit/unit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package unit

import "github.com/bububa/kwai-marketing-api/model/target"
import (
"github.com/bububa/kwai-marketing-api/model"
"github.com/bububa/kwai-marketing-api/model/target"
)

// Unit 广告组
type Unit struct {
Expand Down Expand Up @@ -131,7 +134,7 @@ type Unit struct {
// OuterID 商品ID; sdpa类型广告组才会存在
OuterID string `json:"outer_id,omitempty"`
// ProductID 商品ID; sdpa类型广告组才会存在
ProductID uint64 `json:"product_id,omitempty"`
ProductID model.Uint64 `json:"product_id,omitempty"`
// ProductName 商品名称; sdpa类型广告组才会存在
ProductName string `json:"product_name,omitempty"`
// ProductPrice 商品价格; 单位:元,sdpa类型广告组才会存在
Expand Down

0 comments on commit 1ca9635

Please sign in to comment.