Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
3e92c9d9
Commit
3e92c9d9
authored
Dec 08, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nil默认
parent
cca51f65
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
IfUtil.go
util/IfUtil.go
+4
-1
StringUtil_test.go
util/StringUtil_test.go
+8
-3
No files found.
util/IfUtil.go
View file @
3e92c9d9
...
...
@@ -8,5 +8,8 @@ func If[K any](isTrue bool, a, b K) K {
}
func
IfNull
[
K
any
](
a
*
K
,
defaultValue
K
)
K
{
return
If
(
a
==
nil
,
defaultValue
,
*
a
)
if
a
==
nil
{
return
defaultValue
}
return
*
a
}
util/StringUtil_test.go
View file @
3e92c9d9
...
...
@@ -11,10 +11,15 @@ func TestContainsForSplitComma(t *testing.T) {
fmt
.
Printf
(
"%s是否包含在[%s]中:%v"
,
a
,
b
,
ContainsForSplitComma
(
b
,
a
))
}
type
DefaultCount
struct
{
Count
*
int32
`gorm:"column:count" json:"count"`
// 笔数
Money
*
float64
`gorm:"column:money" json:"money"`
// 金额(元)
}
func
TestStrval
(
t
*
testing
.
T
)
{
fmt
.
Printf
(
"转换内容:%s"
,
GetInterfaceToString
(
3.10
))
var
a
i
nt
a
=
If
(
true
,
12
,
0
)
a
=
IfNull
(
&
a
,
0
)
var
count
DefaultCou
nt
//a := If(count.Count == nil
, 12, 0)
a
:=
IfNull
(
count
.
Count
,
0
)
fmt
.
Printf
(
"结果:%d"
,
a
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment