From 5eb61f623a919fcb1351479b8cecc0da1772dd15 Mon Sep 17 00:00:00 2001 From: Scott Nichols <32305648+n3wscott@users.noreply.github.com> Date: Wed, 10 Apr 2019 10:06:58 -0700 Subject: [PATCH] Adding string pointer. (#380) --- ptr/ptr.go | 6 ++++++ ptr/ptr_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/ptr/ptr.go b/ptr/ptr.go index a377f4aff..bd67d8600 100644 --- a/ptr/ptr.go +++ b/ptr/ptr.go @@ -27,3 +27,9 @@ func Int64(i int64) *int64 { func Bool(b bool) *bool { return &b } + +// String is a helper for turning strings into pointers for use in +// API types that want *string. +func String(s string) *string { + return &s +} diff --git a/ptr/ptr_test.go b/ptr/ptr_test.go index 63fe51b25..e8e26a7e2 100644 --- a/ptr/ptr_test.go +++ b/ptr/ptr_test.go @@ -33,3 +33,11 @@ func TestBool(t *testing.T) { t.Errorf("Bool() = &%v, wanted %v", *gotPtr, want) } } + +func TestString(t *testing.T) { + want := "should be a pointer" + gotPtr := String(want) + if want != *gotPtr { + t.Errorf("String() = &%v, wanted %v", *gotPtr, want) + } +}