github.com/blend/go-sdk@v1.20220411.3/configutil/lazy_bool.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 ( 11 "context" 12 ) 13 14 // LazyBool returns an BoolSource for a given bool pointer. 15 // 16 // LazyBool differs from Bool in that it treats false values as unset. 17 // If false is a valid value, use a Bool. 18 func LazyBool(value *bool) LazyBoolSource { 19 return LazyBoolSource{Value: value} 20 } 21 22 var ( 23 _ BoolSource = (*LazyBoolSource)(nil) 24 ) 25 26 // LazyBoolSource implements value provider. 27 // 28 // Note: LazyDuration treats 0 as unset, if 0 is a valid value you must use configutil.DurationPtr. 29 type LazyBoolSource struct { 30 Value *bool 31 } 32 33 // Bool returns the value for a constant. 34 func (i LazyBoolSource) Bool(_ context.Context) (*bool, error) { 35 if i.Value != nil && *i.Value { 36 return i.Value, nil 37 } 38 return nil, nil 39 }