I don't think you need to worry about whether the caller has properly 
registered a service, personally.  That would be the caller's 
responsibility.

An alternate way to make a library of this kind would be to have a type 
like this:

type Server struct {
  GRPC *grpc.Server
  lis net.Listener
}

func NewServer() *Server // initialize GRPC and lis appropriately
func (s *Server) Serve() error // call GRPC.Serve(lis)
func (s *Server) Close() error // stop GRPC and lis

With this model, the user would be responsible for making sure they 
register their services properly before calling Serve, and you wouldn't 
need to pass a lambda around.

Doug


On Tuesday, October 30, 2018 at 7:00:46 PM UTC-7, [email protected] 
wrote:
>
> Hi,
> I was creating a library which allows creating the basic GRPC server for a 
> client of the library and also running the grpc.Serve method on behalf of 
> the client.
> The client of the library provides a function value which performs the 
> Service Registration function. This is passed to the library as a 
> func(){ /* register service code */ }
>
> However, I felt that before calling 
> grpc.Serve()
>
> , I should check if the service has been registered by checking the output 
> of 
> GetServiceInfo()
>
> from the GRPC Server which is newly created. If this is nil, then return 
> an error to the client of the library indicating that the service has not 
> been registered and that the client needs to pass in a registration 
> function (which is generated by the protoc compiler)
>
> Is this a good idea to provide this sort of functionality/error handling 
> when exposing GRPC boilerplate (such as creating a listener, GRPC 
> server,etc.) via a custom library package ?
>
> Regards,
> N
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/57833170-59e8-4191-980a-62325fece9ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to