mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Replace Optional{Int,Int64,Float64} with a generic function OptionalNumber()
This commit is contained in:
parent
c29ca0e313
commit
f6404290ba
3 changed files with 16 additions and 30 deletions
|
@ -3,34 +3,20 @@
|
|||
|
||||
package model // import "miniflux.app/v2/internal/model"
|
||||
|
||||
// OptionalString populates an optional string field.
|
||||
type Number interface {
|
||||
int | int64 | float64
|
||||
}
|
||||
|
||||
func OptionalNumber[T Number](value T) *T {
|
||||
if value > 0 {
|
||||
return &value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func OptionalString(value string) *string {
|
||||
if value != "" {
|
||||
return &value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// OptionalInt populates an optional int field.
|
||||
func OptionalInt(value int) *int {
|
||||
if value > 0 {
|
||||
return &value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// OptionalInt64 populates an optional int64 field.
|
||||
func OptionalInt64(value int64) *int64 {
|
||||
if value > 0 {
|
||||
return &value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// OptionalFloat populates an optional float64 field.
|
||||
func OptionalFloat(value float64) *float64 {
|
||||
if value > 0 {
|
||||
return &value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue