github.com/jxskiss/gopkg@v0.17.3/ptr/deref.go (about) 1 package ptr 2 3 import "time" 4 5 func DerefBool(p *bool) bool { 6 if p != nil { 7 return *p 8 } 9 return false 10 } 11 12 func DerefString(p *string) string { 13 if p != nil { 14 return *p 15 } 16 return "" 17 } 18 19 func DerefInt(p *int) int { 20 if p != nil { 21 return *p 22 } 23 return 0 24 } 25 26 func DerefInt8(p *int8) int8 { 27 if p != nil { 28 return *p 29 } 30 return 0 31 } 32 33 func DerefInt16(p *int16) int16 { 34 if p != nil { 35 return *p 36 } 37 return 0 38 } 39 40 func DerefInt32(p *int32) int32 { 41 if p != nil { 42 return *p 43 } 44 return 0 45 } 46 47 func DerefInt64(p *int64) int64 { 48 if p != nil { 49 return *p 50 } 51 return 0 52 } 53 54 func DerefUint(p *uint) uint { 55 if p != nil { 56 return *p 57 } 58 return 0 59 } 60 61 func DerefUint8(p *uint8) uint8 { 62 if p != nil { 63 return *p 64 } 65 return 0 66 } 67 68 func DerefUint16(p *uint16) uint16 { 69 if p != nil { 70 return *p 71 } 72 return 0 73 } 74 75 func DerefUint32(p *uint32) uint32 { 76 if p != nil { 77 return *p 78 } 79 return 0 80 } 81 82 func DerefUint64(p *uint64) uint64 { 83 if p != nil { 84 return *p 85 } 86 return 0 87 } 88 89 func DerefFloat32(p *float32) float32 { 90 if p != nil { 91 return *p 92 } 93 return 0 94 } 95 96 func DerefFloat64(p *float64) float64 { 97 if p != nil { 98 return *p 99 } 100 return 0 101 } 102 103 func DerefTime(p *time.Time) time.Time { 104 if p != nil { 105 return *p 106 } 107 return time.Time{} 108 } 109 110 func DerefDuration(p *time.Duration) time.Duration { 111 if p != nil { 112 return *p 113 } 114 return 0 115 }