github.com/blend/go-sdk@v1.20220411.3/configutil/resolve_if.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  // ResolveIf wraps a resolver in a branch.
    13  func ResolveIf(branch bool, resolver ResolveAction) ResolveAction {
    14  	return func(ctx context.Context) error {
    15  		if branch {
    16  			return resolver(ctx)
    17  		}
    18  		return nil
    19  	}
    20  }
    21  
    22  // ResolveIfFunc wraps a resolver in a branch returned from a function.
    23  func ResolveIfFunc(branchFunc func(context.Context) bool, resolver ResolveAction) ResolveAction {
    24  	return func(ctx context.Context) error {
    25  		if branchFunc(ctx) {
    26  			return resolver(ctx)
    27  		}
    28  		return nil
    29  	}
    30  }