2020-05-04 10:58:20 -04:00
|
|
|
package api
|
|
|
|
|
|
2020-05-04 23:02:18 -04:00
|
|
|
import "github.com/fatih/structs"
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Bool returns the given bool as a bool pointer
|
2020-05-04 10:58:20 -04:00
|
|
|
func Bool(in bool) *bool {
|
|
|
|
|
ret := new(bool)
|
|
|
|
|
*ret = in
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 23:02:18 -04:00
|
|
|
// String returns the given string as a string pointer
|
2020-05-04 10:58:20 -04:00
|
|
|
func String(in string) *string {
|
|
|
|
|
ret := new(string)
|
|
|
|
|
*ret = in
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 23:02:18 -04:00
|
|
|
// StringOrNil is like String, but the returned pointer will be nil if the
|
|
|
|
|
// string is empty
|
|
|
|
|
func StringOrNil(in string) *string {
|
|
|
|
|
if in == "" {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return String(in)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Int returns the given int64 as an int64 pointer
|
2020-05-26 13:46:21 -07:00
|
|
|
func Int(in int32) *int32 {
|
|
|
|
|
ret := new(int32)
|
2020-05-04 10:58:20 -04:00
|
|
|
*ret = in
|
|
|
|
|
return ret
|
|
|
|
|
}
|
2020-05-04 23:02:18 -04:00
|
|
|
|
|
|
|
|
// IntOrNil is like Int, but the returned pointer will be nil if the integer is
|
|
|
|
|
// 0
|
2020-05-26 13:46:21 -07:00
|
|
|
func IntOrNil(in int32) *int32 {
|
2020-05-04 23:02:18 -04:00
|
|
|
if in == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return Int(in)
|
|
|
|
|
}
|