app-cloudep-trade-service/internal/logic/orderservice/utils.go

29 lines
570 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package orderservicelogic
import (
"github.com/shopspring/decimal"
)
// getInt64Value 將 *int64 的值返回,如果為 nil 則返回 0
func getInt64Value(val *int64) int64 {
if val == nil {
return 0
}
return *val
}
// stringToDecimalPtr 將 *string 轉換為 *decimal.Decimal如果解析失敗或值為 nil 則返回 nil
func stringToDecimalPtr(s *string) *decimal.Decimal {
if s == nil {
return nil
}
dec, err := decimal.NewFromString(*s)
if err != nil {
return nil // 解析失敗時返回 nil或根據需求記錄錯誤
}
return &dec
}