Yimaru-BackEnd/internal/domain/common.go
2025-04-23 03:44:17 +03:00

52 lines
839 B
Go

package domain
import "fmt"
type ValidInt64 struct {
Value int64
Valid bool
}
type ValidString struct {
Value string
Valid bool
}
type ValidBool struct {
Value bool
Valid bool
}
type Currency int64
// ToCurrency converts a float32 to Currency
func ToCurrency(f float32) Currency {
return Currency((f * 100) + 0.5)
}
// Float64 converts a Currency to float32
func (m Currency) Float64() float32 {
x := float32(m)
x = x / 100
return x
}
// String returns a formatted Currency value
func (m Currency) String() string {
x := float32(m)
x = x / 100
return fmt.Sprintf("$%.2f", x)
}
type OutcomeStatus int
const (
OUTCOME_STATUS_PENDING OutcomeStatus = iota
OUTCOME_STATUS_WIN
OUTCOME_STATUS_LOSS
OUTCOME_STATUS_ERROR
)
func (b OutcomeStatus) String() string {
return []string{"Pending", "Win", "Loss", "Error"}[b]
}