github.com/corverroos/quorum@v21.1.0+incompatible/private/engine/config.go (about)

     1  package engine
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/BurntSushi/toml"
     8  )
     9  
    10  type Config struct {
    11  	Socket  string `toml:"socket"`  // socket filename
    12  	WorkDir string `toml:"workdir"` // path to socket file
    13  
    14  	DialTimeout           uint // timeout for connecting to socket (seconds)
    15  	RequestTimeout        uint // timeout for writing to socket (seconds)
    16  	ResponseHeaderTimeout uint // timeout for reading from socket (seconds)
    17  
    18  	// Deprecated
    19  	SocketPath string `toml:"socketPath"`
    20  }
    21  
    22  var DefaultConfig = Config{
    23  	DialTimeout:           1,
    24  	RequestTimeout:        5,
    25  	ResponseHeaderTimeout: 5,
    26  }
    27  
    28  // LoadConfig sets up the configuration for the connection to a txn manager.
    29  // It will accept a path to a socket file or a path to a config file,
    30  // and returns the full configuration info for the socket file.
    31  func LoadConfig(path string) (Config, error) {
    32  	info, err := os.Lstat(path)
    33  	if err != nil {
    34  		return Config{}, err
    35  	}
    36  
    37  	cfg := DefaultConfig
    38  	isSocket := info.Mode()&os.ModeSocket != 0
    39  	if !isSocket {
    40  		if _, err := toml.DecodeFile(path, &cfg); err != nil {
    41  			return Config{}, err
    42  		}
    43  	} else {
    44  		cfg.WorkDir, cfg.Socket = filepath.Split(path)
    45  	}
    46  
    47  	// Fall back to Constellation 0.0.1 config format if necessary
    48  	if cfg.Socket == "" {
    49  		cfg.Socket = cfg.SocketPath
    50  	}
    51  	return cfg, nil
    52  }