github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/internal/pkg/gateway/config/options.go (about)

     1  /*
     2  Copyright hechain. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package config
     8  
     9  import (
    10  	"time"
    11  
    12  	"github.com/spf13/viper"
    13  )
    14  
    15  // GatewayOptions is used to configure the gateway settings.
    16  type Options struct {
    17  	// GatewayEnabled is used to enable the gateway service.
    18  	Enabled bool
    19  	// EndorsementTimeout is used to specify the maximum time to wait for endorsement responses from external peers.
    20  	EndorsementTimeout time.Duration
    21  	// DialTimeout is used to specify the maximum time to wait for connecting to external peers and orderer nodes.
    22  	DialTimeout time.Duration
    23  }
    24  
    25  var defaultOptions = Options{
    26  	Enabled:            true,
    27  	EndorsementTimeout: 10 * time.Second,
    28  	DialTimeout:        30 * time.Second,
    29  }
    30  
    31  // DefaultOptions gets the default Gateway configuration Options
    32  func GetOptions(v *viper.Viper) Options {
    33  	options := defaultOptions
    34  	if v.IsSet("peer.gateway.enabled") {
    35  		options.Enabled = v.GetBool("peer.gateway.enabled")
    36  	}
    37  	if v.IsSet("peer.gateway.endorsementTimeout") {
    38  		options.EndorsementTimeout = v.GetDuration("peer.gateway.endorsementTimeout")
    39  	}
    40  	if v.IsSet("peer.gateway.dialTimeout") {
    41  		options.DialTimeout = v.GetDuration("peer.gateway.dialTimeout")
    42  	}
    43  
    44  	return options
    45  }