unregister.go 628 Bytes
Newer Older
Richer Maximilien's avatar
Richer Maximilien committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
package user

import (
	"errors"

	"golang.org/x/net/context"
	"google.golang.org/grpc"

	pb "dfss/dfssp/api"
	"dfss/net"
)

// Unregister a user from the platform
func Unregister() error {
	client, err := connect()
	if err != nil {
		return err
	}

	// Stop the context if it takes too long for the platform to answer
	ctx, cancel := context.WithTimeout(context.Background(), net.DefaultTimeout)
	defer cancel()
	response, err := client.Unregister(ctx, &pb.Empty{})
	if err != nil {
		return errors.New(grpc.ErrorDesc(err))
	}
	if response.Code != pb.ErrorCode_SUCCESS {
		return errors.New(response.Message)
	}

	return nil
}