formatted code with gofmt

This commit is contained in:
Bernhard B 2021-09-11 22:30:56 +02:00
parent ae857c7a69
commit 27b7f28c42
2 changed files with 22 additions and 24 deletions

View File

@ -1,12 +1,12 @@
package client package client
import ( import (
"bufio"
"encoding/json" "encoding/json"
"errors" "errors"
"net"
"bufio"
uuid "github.com/gofrs/uuid" uuid "github.com/gofrs/uuid"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net"
) )
type JsonRpc2Client struct { type JsonRpc2Client struct {
@ -14,37 +14,36 @@ type JsonRpc2Client struct {
} }
func NewJsonRpc2Client() *JsonRpc2Client { func NewJsonRpc2Client() *JsonRpc2Client {
return &JsonRpc2Client{ return &JsonRpc2Client{}
}
} }
func (r *JsonRpc2Client) Dial(address string) error { func (r *JsonRpc2Client) Dial(address string) error {
var err error var err error
r.conn, err = net.Dial("tcp", address) r.conn, err = net.Dial("tcp", address)
if err != nil { if err != nil {
return err return err
} }
return nil return nil
} }
func (r *JsonRpc2Client) getRaw(command string, args interface{}) (string, error) { func (r *JsonRpc2Client) getRaw(command string, args interface{}) (string, error) {
type Request struct { type Request struct {
JsonRpc string `json:"jsonrpc"` JsonRpc string `json:"jsonrpc"`
Method string `json:"method"` Method string `json:"method"`
Id string `json:"id"` Id string `json:"id"`
Params interface{} `json:"params,omitempty"` Params interface{} `json:"params,omitempty"`
} }
type Error struct { type Error struct {
Code int `json:"code"` Code int `json:"code"`
Message string `json:"message"` Message string `json:"message"`
} }
type Response struct { type Response struct {
Id string `json:"id"` Id string `json:"id"`
Result json.RawMessage `json:"result"` Result json.RawMessage `json:"result"`
Err Error `json:"error"` Err Error `json:"error"`
} }
u, err := uuid.NewV4() u, err := uuid.NewV4()
@ -65,9 +64,9 @@ func (r *JsonRpc2Client) getRaw(command string, args interface{}) (string, error
log.Info("request = ", string(fullCommandBytes)) log.Info("request = ", string(fullCommandBytes))
_, err = r.conn.Write([]byte(string(fullCommandBytes) + "\n")) _, err = r.conn.Write([]byte(string(fullCommandBytes) + "\n"))
if err != nil { if err != nil {
return "", err return "", err
} }
connbuf := bufio.NewReader(r.conn) connbuf := bufio.NewReader(r.conn)
for { for {

View File

@ -1,18 +1,18 @@
package utils package utils
import ( import (
"io/ioutil"
"errors" "errors"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"io/ioutil"
) )
type ConfigEntry struct { type ConfigEntry struct {
TcpPort int64 `yaml:"tcp_port"` TcpPort int64 `yaml:"tcp_port"`
FifoPathname string `yaml:"fifo_pathname"` FifoPathname string `yaml:"fifo_pathname"`
} }
type Config struct { type Config struct {
Entries map[string]ConfigEntry `yaml:"config,omitempty"` Entries map[string]ConfigEntry `yaml:"config,omitempty"`
} }
type JsonRpc2ClientConfig struct { type JsonRpc2ClientConfig struct {
@ -20,8 +20,7 @@ type JsonRpc2ClientConfig struct {
} }
func NewJsonRpc2ClientConfig() *JsonRpc2ClientConfig { func NewJsonRpc2ClientConfig() *JsonRpc2ClientConfig {
return &JsonRpc2ClientConfig{ return &JsonRpc2ClientConfig{}
}
} }
func (c *JsonRpc2ClientConfig) Load(path string) error { func (c *JsonRpc2ClientConfig) Load(path string) error {
@ -43,7 +42,7 @@ func (c *JsonRpc2ClientConfig) GetTcpPortForNumber(number string) (int64, error)
return val.TcpPort, nil return val.TcpPort, nil
} }
return 0, errors.New("No number found") return 0, errors.New("Number " + number + " not found in local map")
} }
func (c *JsonRpc2ClientConfig) GetFifoPathnameForNumber(number string) (string, error) { func (c *JsonRpc2ClientConfig) GetFifoPathnameForNumber(number string) (string, error) {
@ -51,7 +50,7 @@ func (c *JsonRpc2ClientConfig) GetFifoPathnameForNumber(number string) (string,
return val.FifoPathname, nil return val.FifoPathname, nil
} }
return "", errors.New("No number found") return "", errors.New("Number " + number + " not found in local map")
} }
func (c *JsonRpc2ClientConfig) GetTcpPortsForNumbers() map[string]int64 { func (c *JsonRpc2ClientConfig) GetTcpPortsForNumbers() map[string]int64 {