Skip to content
Snippets Groups Projects
rbac.go 1.55 KiB
Newer Older
  • Learn to ignore specific revisions
  • package client
    
    import (
    	apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
    	"google.golang.org/grpc"
    )
    
    
    var authClientConnection *grpc.ClientConn
    var userClientConnection *grpc.ClientConn
    var roleClientConnection *grpc.ClientConn
    
    
    // AuthClient returns a client for the gRPC Auth service. It takes
    // the address of the gRPC endpoint and optional grpc.DialOption
    
    func AuthClient(addr string, opts ...grpc.DialOption) (apb.AuthServiceClient, error) {
    
    	var err error
    
    	if authClientConnection == nil {
    		authClientConnection, err = grpc.NewClient(addr, opts...)
    		if err != nil {
    			return nil, err
    		}
    
    	return apb.NewAuthServiceClient(authClientConnection), nil
    
    
    // UserClient returns a client for the gRPC User service. It takes
    // the address of the gRPC endpoint and optional grpc.DialOption
    
    func UserClient(addr string, opts ...grpc.DialOption) (apb.UserServiceClient, error) {
    
    	var err error
    
    	if userClientConnection == nil {
    		userClientConnection, err = grpc.NewClient(addr, opts...)
    		if err != nil {
    			return nil, err
    		}
    
    	return apb.NewUserServiceClient(userClientConnection), nil
    
    }
    
    // RoleClient returns a client for the gRPC Role service. It takes
    // the address of the gRPC endpoint and optional grpc.DialOption
    
    func RoleClient(addr string, opts ...grpc.DialOption) (apb.RoleServiceClient, error) {
    
    	var err error
    
    	if roleClientConnection == nil {
    		roleClientConnection, err = grpc.NewClient(addr, opts...)
    		if err != nil {
    			return nil, err
    		}
    
    	return apb.NewRoleServiceClient(roleClientConnection), nil