vendor: add github.com/Azure/go-autorest/autorest/to

This commit is contained in:
Michael Leow 2017-05-24 09:25:43 +02:00 committed by Frank Schroeder
parent bdaf9d6ba9
commit 447413bf99
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD
2 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,133 @@
/*
Package to provides helpers to ease working with pointer values of marshalled structures.
*/
package to
// String returns a string value for the passed string pointer. It returns the empty string if the
// pointer is nil.
func String(s *string) string {
if s != nil {
return *s
}
return ""
}
// StringPtr returns a pointer to the passed string.
func StringPtr(s string) *string {
return &s
}
// StringSlice returns a string slice value for the passed string slice pointer. It returns a nil
// slice if the pointer is nil.
func StringSlice(s *[]string) []string {
if s != nil {
return *s
}
return nil
}
// StringSlicePtr returns a pointer to the passed string slice.
func StringSlicePtr(s []string) *[]string {
return &s
}
// StringMap returns a map of strings built from the map of string pointers. The empty string is
// used for nil pointers.
func StringMap(msp map[string]*string) map[string]string {
ms := make(map[string]string, len(msp))
for k, sp := range msp {
if sp != nil {
ms[k] = *sp
} else {
ms[k] = ""
}
}
return ms
}
// StringMapPtr returns a pointer to a map of string pointers built from the passed map of strings.
func StringMapPtr(ms map[string]string) *map[string]*string {
msp := make(map[string]*string, len(ms))
for k, s := range ms {
msp[k] = StringPtr(s)
}
return &msp
}
// Bool returns a bool value for the passed bool pointer. It returns false if the pointer is nil.
func Bool(b *bool) bool {
if b != nil {
return *b
}
return false
}
// BoolPtr returns a pointer to the passed bool.
func BoolPtr(b bool) *bool {
return &b
}
// Int returns an int value for the passed int pointer. It returns 0 if the pointer is nil.
func Int(i *int) int {
if i != nil {
return *i
}
return 0
}
// IntPtr returns a pointer to the passed int.
func IntPtr(i int) *int {
return &i
}
// Int32 returns an int value for the passed int pointer. It returns 0 if the pointer is nil.
func Int32(i *int32) int32 {
if i != nil {
return *i
}
return 0
}
// Int32Ptr returns a pointer to the passed int32.
func Int32Ptr(i int32) *int32 {
return &i
}
// Int64 returns an int value for the passed int pointer. It returns 0 if the pointer is nil.
func Int64(i *int64) int64 {
if i != nil {
return *i
}
return 0
}
// Int64Ptr returns a pointer to the passed int64.
func Int64Ptr(i int64) *int64 {
return &i
}
// Float32 returns an int value for the passed int pointer. It returns 0.0 if the pointer is nil.
func Float32(i *float32) float32 {
if i != nil {
return *i
}
return 0.0
}
// Float32Ptr returns a pointer to the passed float32.
func Float32Ptr(i float32) *float32 {
return &i
}
// Float64 returns an int value for the passed int pointer. It returns 0.0 if the pointer is nil.
func Float64(i *float64) float64 {
if i != nil {
return *i
}
return 0.0
}
// Float64Ptr returns a pointer to the passed float64.
func Float64Ptr(i float64) *float64 {
return &i
}

5
vendor/vendor.json vendored
View File

@ -46,6 +46,11 @@
}, },
{ {
"checksumSHA1": "Ev8qCsbFjDlMlX0N2tYAhYQFpUc=", "checksumSHA1": "Ev8qCsbFjDlMlX0N2tYAhYQFpUc=",
"path": "github.com/Azure/go-autorest/autorest/to",
"revision": "c2571aa487482a987546c123fef9334582786335",
"revisionTime": "2017-04-20T22:41:48Z"
},
{
"checksumSHA1": "oBixceM+55gdk47iff8DSEIh3po=", "checksumSHA1": "oBixceM+55gdk47iff8DSEIh3po=",
"path": "github.com/Azure/go-autorest/autorest/validation", "path": "github.com/Azure/go-autorest/autorest/validation",
"revision": "c2571aa487482a987546c123fef9334582786335", "revision": "c2571aa487482a987546c123fef9334582786335",