github.com/blend/go-sdk@v1.20220411.3/configutil/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 "context"
    11  
    12  // BoolSource is a type that can return a value.
    13  type BoolSource interface {
    14  	// Bool should return a bool if the source has a given value.
    15  	// It should return nil if the value is not found.
    16  	// It should return an error if there was a problem fetching the value.
    17  	Bool(context.Context) (*bool, error)
    18  }
    19  
    20  var (
    21  	_ BoolSource = (*BoolValue)(nil)
    22  )
    23  
    24  // Bool returns a BoolValue for a given value.
    25  func Bool(value *bool) *BoolValue {
    26  	if value == nil {
    27  		return nil
    28  	}
    29  	typed := BoolValue(*value)
    30  	return &typed
    31  }
    32  
    33  // BoolValue implements value provider.
    34  type BoolValue bool
    35  
    36  // Bool returns the value for a constant.
    37  func (b *BoolValue) Bool(_ context.Context) (*bool, error) {
    38  	if b == nil {
    39  		return nil, nil
    40  	}
    41  	value := *b
    42  	typed := bool(value)
    43  	return &typed, nil
    44  }