github.com/blend/go-sdk@v1.20220411.3/configutil/string.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 // StringSource is a type that can return a value. 13 type StringSource interface { 14 // String should return a string if the source has a given value. 15 // It should return nil if the value is not present. 16 // It should return an error if there was a problem fetching the value. 17 String(context.Context) (*string, error) 18 } 19 20 var ( 21 _ StringSource = (*String)(nil) 22 ) 23 24 // String implements value provider. 25 // An empty string is treated as unset, and will cause `String(context.Context) (*string, error)` to return 26 // nil for the string. 27 type String string 28 29 // StringValue returns the value for a constant. 30 func (s String) String(_ context.Context) (*string, error) { 31 value := string(s) 32 if value == "" { 33 return nil, nil 34 } 35 return &value, nil 36 }