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