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