0PricingLogin
Go Academy · Lesson

Implementing a Unary gRPC Service

Server and client with grpc-go

What is a unary RPC?

A unary RPC is the simplest gRPC pattern: the client sends one request and receives one response, similar to a regular function call over the network.

Server implementation

Implement the generated interface. Embed the Unimplemented*Server struct for forward compatibility:

type userServer struct {
    pb.UnimplementedUserServiceServer
    db *sql.DB
}

func (s *userServer) GetUser(ctx context.Context, req *pb.GetUserRequest) (*pb.User, error) {
    // query DB
    return &pb.User{Id: req.Id, Name: "Alice"}, nil
}

All lessons in this course

  1. Protocol Buffers and .proto Files
  2. Implementing a Unary gRPC Service
  3. Server and Client Streaming
  4. gRPC Interceptors and Metadata
← Back to Go Academy