Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
golib
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaia-X
Trust Services API
golib
Commits
6d95600d
Commit
6d95600d
authored
3 years ago
by
Yordan Kinkov
Browse files
Options
Downloads
Patches
Plain Diff
add ptr package
parent
17e4c53e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
Add ptr package
Pipeline
#49199
passed with stage
Stage:
in 32 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ptr/ptr.go
+91
-0
91 additions, 0 deletions
ptr/ptr.go
ptr/ptr_test.go
+80
-0
80 additions, 0 deletions
ptr/ptr_test.go
with
171 additions
and
0 deletions
ptr/ptr.go
0 → 100644
+
91
−
0
View file @
6d95600d
/*
Package ptr contains utility functions for converting values to pointer values.
*/
package
ptr
import
"time"
// Bool returns a pointer to a bool value.
func
Bool
(
b
bool
)
*
bool
{
return
&
b
}
// Byte returns a pointer to a byte value.
func
Byte
(
b
byte
)
*
byte
{
return
&
b
}
// Int returns a pointer to an int value.
func
Int
(
i
int
)
*
int
{
return
&
i
}
// Int8 returns a pointer to an int8 value.
func
Int8
(
i
int8
)
*
int8
{
return
&
i
}
// Int16 returns a pointer to an int16 value.
func
Int16
(
i
int16
)
*
int16
{
return
&
i
}
// Int32 returns a pointer to an int32 value.
func
Int32
(
i
int32
)
*
int32
{
return
&
i
}
// Int64 returns a pointer to an int64 value.
func
Int64
(
i
int64
)
*
int64
{
return
&
i
}
// Uint returns a pointer to a uint value.
func
Uint
(
u
uint
)
*
uint
{
return
&
u
}
// Uint8 returns a pointer to a uint8 value.
func
Uint8
(
u
uint8
)
*
uint8
{
return
&
u
}
// Uint16 returns a pointer to a uint16 value.
func
Uint16
(
u
uint16
)
*
uint16
{
return
&
u
}
// Uint32 returns a pointer to a uint32 value.
func
Uint32
(
u
uint32
)
*
uint32
{
return
&
u
}
// Uint64 returns a pointer to a uint64 value.
func
Uint64
(
u
uint64
)
*
uint64
{
return
&
u
}
// Float32 returns a pointer to a float32 value.
func
Float32
(
f
float32
)
*
float32
{
return
&
f
}
// Float64 returns a pointer to a float64 value.
func
Float64
(
f
float64
)
*
float64
{
return
&
f
}
// Rune returns a pointer to a rune value.
func
Rune
(
r
rune
)
*
rune
{
return
&
r
}
// String returns a pointer to a string value.
func
String
(
s
string
)
*
string
{
return
&
s
}
// Time returns a pointer to a time.Time value.
func
Time
(
t
time
.
Time
)
*
time
.
Time
{
return
&
t
}
This diff is collapsed.
Click to expand it.
ptr/ptr_test.go
0 → 100644
+
80
−
0
View file @
6d95600d
package
ptr_test
import
(
"testing"
"time"
"github.com/stretchr/testify/assert"
"code.vereign.com/gaiax/tsa/golib/ptr"
)
func
TestBool
(
t
*
testing
.
T
)
{
assert
.
True
(
t
,
*
ptr
.
Bool
(
true
))
assert
.
False
(
t
,
*
ptr
.
Bool
(
false
))
}
func
TestByte
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
byte
(
64
),
*
ptr
.
Byte
(
64
))
}
func
TestInt
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
int
(
64
),
*
ptr
.
Int
(
64
))
}
func
TestInt8
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
int8
(
64
),
*
ptr
.
Int8
(
64
))
}
func
TestInt16
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
int16
(
64
),
*
ptr
.
Int16
(
64
))
}
func
TestInt32
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
int32
(
64
),
*
ptr
.
Int32
(
64
))
}
func
TestInt64
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
int64
(
64
),
*
ptr
.
Int64
(
64
))
}
func
TestUint
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
uint
(
64
),
*
ptr
.
Uint
(
64
))
}
func
TestUint8
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
uint8
(
64
),
*
ptr
.
Uint8
(
64
))
}
func
TestUint16
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
uint16
(
64
),
*
ptr
.
Uint16
(
64
))
}
func
TestUint32
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
uint32
(
64
),
*
ptr
.
Uint32
(
64
))
}
func
TestUint64
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
uint64
(
64
),
*
ptr
.
Uint64
(
64
))
}
func
TestFloat32
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
float32
(
42.5
),
*
ptr
.
Float32
(
42.5
))
}
func
TestFloat64
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
float64
(
42.5
),
*
ptr
.
Float64
(
42.5
))
}
func
TestRune
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
'r'
,
*
ptr
.
Rune
(
'r'
))
}
func
TestString
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
"mystring"
,
*
ptr
.
String
(
"mystring"
))
}
func
TestTime
(
t
*
testing
.
T
)
{
now
:=
time
.
Now
()
assert
.
Equal
(
t
,
now
,
*
ptr
.
Time
(
now
))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment