github.com/songzhibin97/gkit@v1.2.13/tools/pointer/bool.go (about) 1 package pointer 2 3 // ToBoolPointer 将布尔变量转换为布尔指针 4 func ToBoolPointer(boolValue bool) *bool { 5 return &boolValue 6 } 7 8 // ToBoolPointerOrNilIfFalse 将布尔变量转换为布尔类型的指针,如果变量的值为false的话则转换为nil指针 9 func ToBoolPointerOrNilIfFalse(boolValue bool) *bool { 10 if boolValue { 11 return &boolValue 12 } 13 return nil 14 } 15 16 // FromBoolPointer 获取布尔指针实际指向的值,如果指针为nil的话则返回false 17 func FromBoolPointer(boolPointer *bool) bool { 18 return FromBoolPointerOrDefault(boolPointer, false) 19 } 20 21 // FromBoolPointerOrDefault 获取布尔指针实际指向的值,如果指针为nil的话则返回defaultValue 22 func FromBoolPointerOrDefault(boolPointer *bool, defaultValue bool) bool { 23 if boolPointer == nil { 24 return defaultValue 25 } else { 26 return *boolPointer 27 } 28 }