Commit 4b025e3d authored by ale's avatar ale
Browse files

Refactor client.New to not return an error

Since the GRPC connection is provided externally, nothing can fail.
parent 2947ccc2
......@@ -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 {
......
......@@ -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 {
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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()
}
......
......@@ -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() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment