refactor(time):彻底重构time类型。

This commit is contained in:
徐涛
2023-06-05 22:09:42 +08:00
parent 1fd5e7b9aa
commit 8aa3a054b0
10 changed files with 79 additions and 73 deletions

View File

@@ -133,21 +133,52 @@ func WithSugar(fields ...zap.Field) *zap.SugaredLogger {
return logger.With(fields...).Sugar()
}
func DecimalField(key string, val *decimal.Decimal) zap.Field {
func DecimalField(key string, val decimal.Decimal) zap.Field {
return zap.String(key, val.String())
}
func NullDecimalField(key string, val *decimal.NullDecimal) zap.Field {
func DecimalFieldp(key string, val *decimal.Decimal) zap.Field {
if val == nil {
return zap.String(key, "null")
}
return DecimalField(key, *val)
}
func NullDecimalField(key string, val decimal.NullDecimal) zap.Field {
if val.Valid {
return DecimalField(key, &val.Decimal)
return DecimalField(key, val.Decimal)
}
return zap.String(key, "null")
}
func DateField(key string, val *types.Date) zap.Field {
func NullDecimalFieldp(key string, val *decimal.NullDecimal) zap.Field {
if val == nil {
return zap.String(key, "null")
}
if val.Valid {
return DecimalField(key, val.Decimal)
}
return zap.String(key, "null")
}
func DateField(key string, val types.Date) zap.Field {
return val.Log(key)
}
func DateTimeField(key string, val *types.DateTime) zap.Field {
func DateFieldp(key string, val *types.Date) zap.Field {
if val == nil {
return zap.String(key, "null")
}
return DateField(key, *val)
}
func DateTimeField(key string, val types.DateTime) zap.Field {
return val.Log(key)
}
func DateTimeFieldp(key string, val *types.DateTime) zap.Field {
if val == nil {
return zap.String(key, "null")
}
return DateTimeField(key, *val)
}