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