app-cloudep-trade-service/internal/usecase/utils.go

32 lines
606 B
Go
Raw 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 usecase
import "github.com/shopspring/decimal"
// Int64Ptr 將 int64 類型轉為 *int64若值為 0 則返回 nil
func Int64Ptr(val int64) *int64 {
if val == 0 {
return nil
}
return &val
}
// DecimalToStringPtr 將 decimal.Decimal 指標轉換為 *string若為 nil 則返回 nil
func DecimalToStringPtr(val *decimal.Decimal) *string {
if val == nil {
return nil
}
str := val.String()
return &str
}
// StringPtr 將 *string 或其他欄位直接返回(適合用於已是指標的欄位)
func StringPtr(val string) *string {
if val == "" {
return nil
}
return &val
}