Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Handling incoming gRPC connections

While the constructor returns a new and configured Master instance, it does not automatically start the master's gRPC server. Instead, this task is left to the end user, who must manually invoke the master's Start method:

func (m *Master) Start() error {
    var err error
    if m.srvListener, err = net.Listen("tcp", m.cfg.ListenAddress); err != nil {
        return xerrors.Errorf("cannot start server: %w", err)
    }

    gSrv := grpc.NewServer()
    proto.RegisterJobQueueServer(gSrv, &masterRPCHandler{
        workerPool: m.workerPool,
        logger:     m.cfg.Logger,
    })
    m.cfg.Logger.WithField("addr", m.srvListener.Addr().String()).Info("listening for worker connections")
    go func(l net.Listener) { _ = gSrv.Serve(l) }(m.srvListener)

    return nil
}

As ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content