Skip to content

proposal: strings: Create a string pointer from string constant #63309

Description

@sajjanjyothi

When we want to pass a string pointer to a struct member each time we have to create a separate variable and pass the address of that to the member variable, Which is a pain. This wrapper function will ease all those efforts.
Eg:
type Employee struct{
Name *string
}

To pass a variable in testing , we have to
testName := "hello"

emp := Employee{
Name: &testName,
}

I have added a pull request to address this as #63299
With this function it is

emp: = Employee{
Name: strings.StringPointerFrom("hello")
}

It is really helpful when we are using table tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions