kaspad/cmd/txgen/connect.go
Ori Newman c88fa1492e [NOD-375] Move to pkg/errors (#447)
* [NOD-375] Move to pkg/errors

* [NOD-375] Fix tests

* [NOD-375] Make AreErrorsEqual a shared function
2019-11-04 11:24:12 +02:00

40 lines
798 B
Go

package main
import (
"github.com/daglabs/btcd/rpcclient"
"github.com/pkg/errors"
"io/ioutil"
)
func connectToServer(cfg *config) (*txgenClient, error) {
var cert []byte
if !cfg.DisableTLS {
var err error
cert, err = ioutil.ReadFile(cfg.CertificatePath)
if err != nil {
return nil, errors.Errorf("Error reading certificates file: %s", err)
}
}
connCfg := &rpcclient.ConnConfig{
Host: cfg.Address,
Endpoint: "ws",
User: "user",
Pass: "pass",
DisableTLS: cfg.DisableTLS,
}
if !cfg.DisableTLS {
connCfg.Certificates = cert
}
client, err := newTxgenClient(connCfg)
if err != nil {
return nil, errors.Errorf("Error connecting to address %s: %s", cfg.Address, err)
}
log.Infof("Connected to server %s", cfg.Address)
return client, nil
}