Repository: hashicorp/nomad
File: command/agent/config.go (Go)

Code before:
	}
	if rpc.KeepAliveInterval > 0 {
		result.KeepAliveInterval = rpc.KeepAliveInterval
	}
	if rpc.ConnectionWriteTimeout > 0 {
		result.ConnectionWriteTimeout = rpc.ConnectionWriteTimeout
	}
	if rpc.StreamOpenTimeout > 0 {
		result.StreamOpenTimeout = rpc.StreamOpenTimeout
	}
	if rpc.StreamCloseTimeout > 0 {
		result.StreamCloseTimeout = rpc.StreamCloseTimeout
	}
	return &result
}

func (r *RPCConfig) Validate() error {
	if r != nil {
		if r.AcceptBacklog < 0 {
			return errors.New("rcp.accept_backlog interval must be greater than zero")
		}

		if r.KeepAliveInterval < 0 {
			return errors.New("rcp.keep_alive_interval must be greater than zero")
		}

		if r.ConnectionWriteTimeout < 0 {
			return errors.New("rcp.connection_write_timeout must be greater than zero")
		}
		if r.StreamCloseTimeout < 0 {
			return errors.New("rcp.stream_close_timeout must be greater than zero")
		}
		if r.StreamOpenTimeout < 0 {
			return errors.New("rcp.stream_open_timeout must be greater than zero")
		}
	}

	return nil
}

// RaftBoltConfig is used in servers to configure parameters of the boltdb
// used for raft consensus.
type RaftBoltConfig struct {
	// NoFreelistSync toggles whether the underlying raft storage should sync its
	// freelist to disk within the bolt .db file. When disabled, IO performance
	// will be improved but at the expense of longer startup times.
	//
	// Default: false.
	NoFreelistSync bool `hcl:"no_freelist_sync"`
}


Review comment (suggestion):
Minor aesthetic complaint: these are all the same kind of validation, so let's have the spacing consistent.

```suggestion
		if r.AcceptBacklog < 0 {
			return errors.New("rcp.accept_backlog interval must be greater than zero")
		}
		if r.KeepAliveInterval < 0 {
			return errors.New("rcp.keep_alive_interval must be greater than zero")
		}
```

Code after:
	}
	if rpc.KeepAliveIntervalHCL != "" {
		result.KeepAliveIntervalHCL = rpc.KeepAliveIntervalHCL
	}
	if rpc.KeepAliveInterval > 0 {
		result.KeepAliveInterval = rpc.KeepAliveInterval
	}
	if rpc.ConnectionWriteTimeoutHCL != "" {
		result.ConnectionWriteTimeoutHCL = rpc.ConnectionWriteTimeoutHCL
	}
	if rpc.ConnectionWriteTimeout > 0 {
		result.ConnectionWriteTimeout = rpc.ConnectionWriteTimeout
	}
	if rpc.StreamOpenTimeoutHCL != "" {
		result.StreamOpenTimeoutHCL = rpc.StreamOpenTimeoutHCL
	}
	if rpc.StreamOpenTimeout > 0 {
		result.StreamOpenTimeout = rpc.StreamOpenTimeout
	}
	if rpc.StreamCloseTimeoutHCL != "" {
		result.StreamCloseTimeoutHCL = rpc.StreamCloseTimeoutHCL
	}
	if rpc.StreamCloseTimeout > 0 {
		result.StreamCloseTimeout = rpc.StreamCloseTimeout
	}
	return &result
}

func (r *RPCConfig) Validate() error {
	if r != nil {
		if r.AcceptBacklog < 0 {
			return errors.New("rcp.accept_backlog interval must be greater than zero")
		}
		if r.KeepAliveInterval < 0 {
			return errors.New("rcp.keep_alive_interval must be greater than zero")
		}
		if r.ConnectionWriteTimeout < 0 {
			return errors.New("rcp.connection_write_timeout must be greater than zero")
		}
		if r.StreamCloseTimeout < 0 {
			return errors.New("rcp.stream_close_timeout must be greater than zero")
		}
		if r.StreamOpenTimeout < 0 {
			return errors.New("rcp.stream_open_timeout must be greater than zero")
		}
	}

	return nil
}

// RaftBoltConfig is used in servers to configure parameters of the boltdb