github.com/blend/go-sdk@v1.20220411.3/configutil/string_ptr.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package configutil
     9  
    10  import "context"
    11  
    12  // StringPtr returns a StringSource for a given string pointer.
    13  //
    14  // It differs from LazyString in that you can resolve to an empty string
    15  // with a StringPtr, but a LazyString would treat that as unset.
    16  func StringPtr(value *string) *StringPtrSource {
    17  	return &StringPtrSource{Value: value}
    18  }
    19  
    20  var (
    21  	_ StringSource = (*StringPtrSource)(nil)
    22  )
    23  
    24  // StringPtrSource implements the StringPtr resolver.
    25  type StringPtrSource struct {
    26  	Value *string
    27  }
    28  
    29  // String yields the underlying pointer, which can be an empty string.
    30  func (s *StringPtrSource) String(_ context.Context) (*string, error) {
    31  	return s.Value, nil
    32  }