remove ginext/mongoext (no-dep lib)

This commit is contained in:
2022-10-27 16:07:42 +02:00
parent 568d7bd5e3
commit 47f123b86f
31 changed files with 6 additions and 123 deletions

62
langext/coalesce.go Normal file
View File

@@ -0,0 +1,62 @@
package langext
import (
"fmt"
"time"
)
func Coalesce[T any](v *T, def T) T {
if v == nil {
return def
} else {
return *v
}
}
func CoalesceString(s *string, def string) string {
if s == nil {
return def
} else {
return *s
}
}
func CoalesceInt(i *int, def int) int {
if i == nil {
return def
} else {
return *i
}
}
func CoalesceInt32(i *int32, def int32) int32 {
if i == nil {
return def
} else {
return *i
}
}
func CoalesceBool(b *bool, def bool) bool {
if b == nil {
return def
} else {
return *b
}
}
func CoalesceTime(t *time.Time, def time.Time) time.Time {
if t == nil {
return def
} else {
return *t
}
}
func CoalesceStringer(s fmt.Stringer, def string) string {
if IsNil(s) {
return def
} else {
return s.String()
}
}