mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00

* [NOD-286] Implement API-Server base structure * [NOD-286] Add rpc user and password as command line arguments * [NOD-286] Make log directory a CLI argument * [NOD-286] Add db login details as CLI arguments
40 lines
794 B
Go
40 lines
794 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/daglabs/btcd/rpcclient"
|
|
"io/ioutil"
|
|
)
|
|
|
|
func connectToServer(cfg *config) (*apiServerClient, error) {
|
|
var cert []byte
|
|
if !cfg.DisableTLS {
|
|
var err error
|
|
cert, err = ioutil.ReadFile(cfg.RPCCert)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error reading certificates file: %s", err)
|
|
}
|
|
}
|
|
|
|
connCfg := &rpcclient.ConnConfig{
|
|
Host: cfg.RPCServer,
|
|
Endpoint: "ws",
|
|
User: cfg.RPCUser,
|
|
Pass: cfg.RPCPassword,
|
|
DisableTLS: cfg.DisableTLS,
|
|
}
|
|
|
|
if !cfg.DisableTLS {
|
|
connCfg.Certificates = cert
|
|
}
|
|
|
|
client, err := newAPIServerClient(connCfg)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error connecting to address %s: %s", cfg.RPCServer, err)
|
|
}
|
|
|
|
log.Infof("Connected to server %s", cfg.RPCServer)
|
|
|
|
return client, nil
|
|
}
|