github.com/blend/go-sdk@v1.20220411.3/configutil/duration.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 "time" 13 ) 14 15 var ( 16 _ DurationSource = (*Duration)(nil) 17 ) 18 19 // Duration implements value provider. 20 // 21 // If the value is zero, a nil is returned by the implementation indicating 22 // the value was not present. 23 // 24 // If you want 0 to be a valid value, you must use DurationPtr. 25 type Duration time.Duration 26 27 // Duration returns the value for a constant. 28 func (dc Duration) Duration(_ context.Context) (*time.Duration, error) { 29 if dc > 0 { 30 value := time.Duration(dc) 31 return &value, nil 32 } 33 return nil, nil 34 }