Skip to content

Commit

Permalink
add export function comment
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed Nov 16, 2021
1 parent 31a4089 commit 0aa9df7
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 9 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,4 @@ go get github.com/chyroc/go-ptr

## Usage

doc: https://godoc.org/github.com/chyroc/go-pointer

## Dev

- setup codecov
- setup github secret: CODECOV_TOKEN
- https://app.codecov.io/gh/chyroc/go-ptr
godoc: https://pkg.go.dev/github.com/chyroc/go-ptr
2 changes: 2 additions & 0 deletions p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package ptr

import "time"

// PointerInt64ToTime converts a pointer of type *int64 to a time.Time.
func PointerInt64ToTime(i *int64) *time.Time {
if i == nil {
return nil
}
return Time(time.Unix(*i, 0))
}

// PointerTimeToInt64 converts a pointer of type *time.Time to a int64.
func PointerTimeToInt64(i *time.Time) *int64 {
if i == nil {
return nil
Expand Down
24 changes: 24 additions & 0 deletions pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,101 +5,125 @@ import (
"time"
)

// String returns the pointer of string value
func String(s string) *string {
return &s
}

// Bool ean returns the pointer of boolean value
func Bool(s bool) *bool {
return &s
}

// Byte returns the pointer of byte value
func Byte(s byte) *byte {
return &s
}

// Rune returns the pointer of rune value
func Rune(s rune) *rune {
return &s
}

// Int returns the pointer of int value
func Int(s int) *int {
return &s
}

// Int8 returns the pointer of int8 value
func Int8(s int8) *int8 {
return &s
}

// Int16 returns the pointer of int16 value
func Int16(s int16) *int16 {
return &s
}

// Int32 returns the pointer of int32 value
func Int32(s int32) *int32 {
return &s
}

// Int64 returns the pointer of int64 value
func Int64(s int64) *int64 {
return &s
}

// UInt returns the pointer of uint value
func UInt(s uint) *uint {
return &s
}

// UInt8 returns the pointer of uint8 value
func UInt8(s uint8) *uint8 {
return &s
}

// UInt16 returns the pointer of uint16 value
func UInt16(s uint16) *uint16 {
return &s
}

// UInt32 returns the pointer of uint32 value
func UInt32(s uint32) *uint32 {
return &s
}

// UInt64 returns the pointer of uint64 value
func UInt64(s uint64) *uint64 {
return &s
}

// UIntptr returns the pointer of uintptr value
func UIntptr(s uintptr) *uintptr {
return &s
}

// Float32 returns the pointer of float32 value
func Float32(s float32) *float32 {
return &s
}

// Float64 returns the pointer of float64 value
func Float64(s float64) *float64 {
return &s
}

// Complex64 returns the pointer of complex64 value
func Complex64(s complex64) *complex64 {
return &s
}

// Complex128 returns the pointer of complex128 value
func Complex128(s complex128) *complex128 {
return &s
}

// Error returns the pointer of error value
func Error(s error) *error {
if s == nil {
return nil
}
return &s
}

// Time returns the pointer of time.Time value
func Time(s time.Time) *time.Time {
return &s
}

// Duration returns the pointer of time.Duration value
func Duration(s time.Duration) *time.Duration {
return &s
}

// ReflectValue returns the pointer of reflect.Value value
func ReflectValue(s reflect.Value) *reflect.Value {
return &s
}

// ReflectType returns the pointer of reflect.Type value
func ReflectType(s reflect.Type) *reflect.Type {
return &s
}
22 changes: 22 additions & 0 deletions pointer_no_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,153 +2,175 @@ package ptr

import "time"

// StringNoNonePtr returns the pointer of string value, if the value is zero-value, it returns nil
func StringNoNonePtr(s string) *string {
if s == "" {
return nil
}
return &s
}

// BoolNoNonePtr returns the pointer of bool value, if the value is zero-value, it returns nil
func BoolNoNonePtr(s bool) *bool {
if s == false {
return nil
}
return &s
}

// ByteNoNonePtr returns the pointer of byte value, if the value is zero-value, it returns nil
func ByteNoNonePtr(s byte) *byte {
if s == 0 {
return nil
}
return &s
}

// RuneNoNonePtr returns the pointer of rune value, if the value is zero-value, it returns nil
func RuneNoNonePtr(s rune) *rune {
if s == 0 {
return nil
}
return &s
}

// IntNoNonePtr returns the pointer of int value, if the value is zero-value, it returns nil
func IntNoNonePtr(s int) *int {
if s == 0 {
return nil
}
return &s
}

// Int8NoNonePtr returns the pointer of int8 value, if the value is zero-value, it returns nil
func Int8NoNonePtr(s int8) *int8 {
if s == 0 {
return nil
}
return &s
}

// Int16NoNonePtr returns the pointer of int16 value, if the value is zero-value, it returns nil
func Int16NoNonePtr(s int16) *int16 {
if s == 0 {
return nil
}
return &s
}

// Int32NoNonePtr returns the pointer of int32 value, if the value is zero-value, it returns nil
func Int32NoNonePtr(s int32) *int32 {
if s == 0 {
return nil
}
return &s
}

// Int64NoNonePtr returns the pointer of int64 value, if the value is zero-value, it returns nil
func Int64NoNonePtr(s int64) *int64 {
if s == 0 {
return nil
}
return &s
}

// UIntNoNonePtr returns the pointer of uint value, if the value is zero-value, it returns nil
func UIntNoNonePtr(s uint) *uint {
if s == 0 {
return nil
}
return &s
}

// UInt8NoNonePtr returns the pointer of uint8 value, if the value is zero-value, it returns nil
func UInt8NoNonePtr(s uint8) *uint8 {
if s == 0 {
return nil
}
return &s
}

// UInt16NoNonePtr returns the pointer of uint16 value, if the value is zero-value, it returns nil
func UInt16NoNonePtr(s uint16) *uint16 {
if s == 0 {
return nil
}
return &s
}

// UInt32NoNonePtr returns the pointer of uint32 value, if the value is zero-value, it returns nil
func UInt32NoNonePtr(s uint32) *uint32 {
if s == 0 {
return nil
}
return &s
}

// UInt64NoNonePtr returns the pointer of uint64 value, if the value is zero-value, it returns nil
func UInt64NoNonePtr(s uint64) *uint64 {
if s == 0 {
return nil
}
return &s
}

// UIntptrNoNonePtr returns the pointer of uintptr value, if the value is zero-value, it returns nil
func UIntptrNoNonePtr(s uintptr) *uintptr {
if s == 0 {
return nil
}
return &s
}

// Float32NoNonePtr returns the pointer of float32 value, if the value is zero-value, it returns nil
func Float32NoNonePtr(s float32) *float32 {
if s == 0 {
return nil
}
return &s
}

// Float64NoNonePtr returns the pointer of float64 value, if the value is zero-value, it returns nil
func Float64NoNonePtr(s float64) *float64 {
if s == 0 {
return nil
}
return &s
}

// Complex64NoNonePtr returns the pointer of complex64 value, if the value is zero-value, it returns nil
func Complex64NoNonePtr(s complex64) *complex64 {
if s == 0 {
return nil
}
return &s
}

// Complex128NoNonePtr returns the pointer of complex128 value, if the value is zero-value, it returns nil
func Complex128NoNonePtr(s complex128) *complex128 {
if s == 0 {
return nil
}
return &s
}

// ErrorNoNonePtr returns the pointer of error value, if the value is zero-value, it returns nil
func ErrorNoNonePtr(s error) *error {
if s == nil {
return nil
}
return &s
}

// TimeNoNonePtr returns the pointer of time.Time value, if the value is zero-value, it returns nil
func TimeNoNonePtr(s time.Time) *time.Time {
if s.UnixNano() == 0 {
return nil
}
return &s
}

// DurationNoNonePtr returns the pointer of time.Duration value, if the value is zero-value, it returns nil
func DurationNoNonePtr(s time.Duration) *time.Duration {
if s == 0 {
return nil
Expand Down
2 changes: 0 additions & 2 deletions pointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ func TestUIntptr(t *testing.T) {
as.Equal(v1, ValueUIntptrWithDefault(UIntptrNoNonePtr(v1), v1))
}



func TestReflect(t *testing.T) {
as := assert.New(t)

Expand Down
Loading

0 comments on commit 0aa9df7

Please sign in to comment.