From 4b025e3db6abdc2cfb5aa4808a7c06ea3214a6a2 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Wed, 21 Apr 2021 22:40:58 +0100
Subject: [PATCH] Refactor client.New to not return an error

Since the GRPC connection is provided externally, nothing can fail.
---
 client/conn.go      | 6 +++---
 cmd/iprep/dump.go   | 5 +----
 cmd/iprep/query.go  | 5 +----
 cmd/iprep/submit.go | 5 +----
 cmd/iprep/tail.go   | 5 +----
 submission/queue.go | 8 ++------
 6 files changed, 9 insertions(+), 25 deletions(-)

diff --git a/client/conn.go b/client/conn.go
index d90fe45..73af57e 100644
--- a/client/conn.go
+++ b/client/conn.go
@@ -15,7 +15,7 @@ type Client interface {
 	GetAllScores(context.Context, float32) (<-chan *ippb.GetScoreResponse, error)
 }
 
-func New(conn *grpc.ClientConn) (Client, error) {
+func New(conn *grpc.ClientConn) Client {
 	return newClient(conn)
 }
 
@@ -23,10 +23,10 @@ type rpcClient struct {
 	stub ippb.IpRepClient
 }
 
-func newClient(conn *grpc.ClientConn) (*rpcClient, error) {
+func newClient(conn *grpc.ClientConn) *rpcClient {
 	return &rpcClient{
 		stub: ippb.NewIpRepClient(conn),
-	}, nil
+	}
 }
 
 func (c *rpcClient) Submit(ctx context.Context, events []*ippb.Event, aggr *ippb.Aggregate) error {
diff --git a/cmd/iprep/dump.go b/cmd/iprep/dump.go
index c1e2d4f..8fdb0d9 100644
--- a/cmd/iprep/dump.go
+++ b/cmd/iprep/dump.go
@@ -57,10 +57,7 @@ func (c *dumpCommand) run(ctx context.Context) error {
 	}
 	defer conn.Close()
 
-	client, err := ipclient.New(conn)
-	if err != nil {
-		return err
-	}
+	client := ipclient.New(conn)
 
 	ch, err := client.GetAllScores(ctx, 0)
 	if err != nil {
diff --git a/cmd/iprep/query.go b/cmd/iprep/query.go
index 41bef59..d4e3dea 100644
--- a/cmd/iprep/query.go
+++ b/cmd/iprep/query.go
@@ -58,10 +58,7 @@ func (c *queryCommand) run(ctx context.Context, ip string) error {
 	}
 	defer conn.Close()
 
-	client, err := ipclient.New(conn)
-	if err != nil {
-		return err
-	}
+	client := ipclient.New(conn)
 
 	resp, err := client.GetScore(ctx, ip)
 	if err != nil {
diff --git a/cmd/iprep/submit.go b/cmd/iprep/submit.go
index 5a94809..4cd4f32 100644
--- a/cmd/iprep/submit.go
+++ b/cmd/iprep/submit.go
@@ -65,10 +65,7 @@ func (c *submitCommand) run(ctx context.Context) error {
 	}
 	defer conn.Close()
 
-	client, err := ipclient.New(conn)
-	if err != nil {
-		return err
-	}
+	client := ipclient.New(conn)
 
 	var events []*ippb.Event
 	scanner := bufio.NewScanner(os.Stdin)
diff --git a/cmd/iprep/tail.go b/cmd/iprep/tail.go
index 171f691..df64f82 100644
--- a/cmd/iprep/tail.go
+++ b/cmd/iprep/tail.go
@@ -145,13 +145,10 @@ func (c *tailCommand) run(ctx context.Context) error {
 
 	var sub submission.Submitter
 	if !c.testOnly {
-		sub, err = submission.New(conn, &submission.Options{
+		sub = submission.New(conn, &submission.Options{
 			MaxDelay:  c.maxDelay,
 			MaxStored: c.maxStored,
 		})
-		if err != nil {
-			return err
-		}
 		defer sub.Close()
 	}
 
diff --git a/submission/queue.go b/submission/queue.go
index 1b6385a..bbc1f9f 100644
--- a/submission/queue.go
+++ b/submission/queue.go
@@ -74,13 +74,9 @@ func newSubmitter(client client.Client, opts *Options) Submitter {
 }
 
 // New creates a new Submitter pointing at the specified collector addr.
-func New(conn *grpc.ClientConn, opts *Options) (Submitter, error) {
+func New(conn *grpc.ClientConn, opts *Options) Submitter {
 	opts = opts.withDefaults()
-	c, err := client.New(conn)
-	if err != nil {
-		return nil, err
-	}
-	return newSubmitter(c, opts), nil
+	return newSubmitter(client.New(conn), opts)
 }
 
 func (q *submissionQueue) Close() {
-- 
GitLab